JavaScript, A Programming Language.

JavaScript, A Programming Language.

JavaScript is a programming language, a high-level scripting language meaning it is interpreted and compiled at a run time. It is quite popular right now especially in web development, it is easier and fun to learn than many other programming languages, It is used to create various applications, process data, it is heavily used to write programs that run in web pages, to add interactivity to webpages, it can be used on both client side and server side. It has low barrier to entry all you need to run JavaScript code is an editor and a web browser.

List of Web Browsers for JavaScript
  • Firefox
  • Google Chrome
  • Safari
  • Internet Explorer (from 3.0)
  • Opera
  • Netscape Navigator (from 2.0)....
List of Text Editors for JavaScript
  • Visual Studio
  • Bracket
  • Sublime Text 3
  • Atom
  • Notepad++
  • Neovim....
Online Options

The online options are platforms that allows you to write HTML, CSS & JavaScript code and view the results, they allow you to save your work in the cloud.

How to add JavaScript code to your page

JavaScript tags are <script> the opening tag and </script> the closing tag. It takes language and type attributes but language attribute is deprecated so it should not be used.

Example:
<script type=”text/javascript”> document.write(“Hello World"); </script>

The <script> tag tells us that it is JavaScript. The Type is the attribute. The text/javascript gives the browser information about the data.

Ways to add JavaScript code to your HTML page
  • JavaScript code can be placed in the head section of HTML page
    <html>  
    <head>  
    <title>Welcome to JavaScript</title>
    <script type="text/javascript">  
    function msg(){  
    alert("Hello Javatpoint");  
    }  
    </script>  
    </head> 
    </html>
    
  • JavaScript code can be placed in the body section of the HTML page, just before the body closing tag, this helps improve page load.
    <html>  
    <body>  
    <script type="text/javascript">  
    alert("Hello World!");  
    </script>  
    </body>  
    </html>
    
  • JavaScript can come as an external file meaning JavaScript code can be in a separate file and embed it in HTML page. The file must be saved with .js extension, this method is recommended as it makes code reusable on several pages and it increases the speed of the webpage. External JavaScript is placed in the head section of HTML page, the tag includes source attribute.
    <html>  
    <head> 
    <title>Welcome to JavaScript</title>
    <script scr="sample.js" type="text/javascript" >  
    </script>  
    </head> 
    </html>
    
JavaScript Syntax

Getting used to the rules on how to write instructions is tricky as JavaScript includes a lot of symbols like semicolon ;, parentheses (), curly brackets {}, square bracket [], quotation marks "" ''.... There are arithmetic symbols called Operators such as sum +, assignment =, division /, multiplication *, subtraction -.... and some words like var, console.log, document.write....

JavaScript Comment

When writing code it gets complex and confusing at some point, comments are useful in such situation. Comments does NOT execute. Below are some importance of comment;

  • It is used for explaining code
  • It is used for communicating when working on a project that involves other programmers
  • It is used for delivering messages such as warning and suggestions
  • It makes code easy to read and understand
  • It can be used to avoid running unnecessary code i.e disable code...
Types of JavaScript Comment
  • Single Line Comment; is represented by double forward slash //, it is use before or after the statement.
<script>
// This is a single line comment
document.write ("Hello JavaScript")
</script>

Output:
Hello JavaScript

In the above example, the This is a single line comment was not executed because it is a comment.

  • Single Line Comment; is represented by a front slash line with asterisk and closed with asterisk with forward slash /*....*/. It can be used before, in the middle of and after statement.
<script>
document.write ("My name is Oyindamola, I am a beginner in JavaScript")
/* This is a multi line comment, it will not run */
</script>

Output:
My name is Oyindamola, I am a beginner in JavaScript.

Comments are like figure headed code!

Hope it was helpful. Feel free to like, share and contribute in the comment section. Thanks 😊