JavaScript Syntax

In this tutorial lecture we will learn about JavaScript syntax, You will learn some important features of JavaScript syntax, so let's get started.

What is JavaScript Syntax?

  • JavaScript syntax refers to the set of rules that determine how a JavaScript program is created
  • You will learn some important features of JavaScript syntax, so let's get started.
  • JavaScript syntax refers to a set of rules that determines how a language will be written, with the programmer interpreting it and the browser interpreting it.
  • JavaScript syntax includes sections such as variables, functions, statements, operators, data types, objects, etc.

The following example illustrates how JavaScript works

Syntax Example

Edit it yourself
<script>
  // creat a variable
  var a, b, c;
  // use variable
  a = 5;
  b = 6;
  var c = a + b;
  document.getElementById("example").innerHTML = c;
</script>  
  • javascript Syntax has a variety of sections which are discussed in detail below

JavaScript Comments

Comments are ignored by the JavaScript compiler. It increases the readability of the code.

JavaScript supports single-line and block comments.

Anything written after a double slash // (single line comment) or / * and* /(multi-line comment) is considered a comment and is ignored by the JavaScript compiler.

  • You can easily understand JavaScript Comment by following example.

  <script>
      
  // This is an example of a single line comment

  /* this example
      is multi line
        comment */

  </script>

JavaScript Variables

In the JavaScript programming language, variables are used to store data values

The keywords var, let and const are used to declare JavaScript variables.

In the following example, a is defined as a variable. Then, 5 values are assigned


  <script>
    var a;
    a = 6;
    document.write(a);
  </script>

JavaScript Operators

JavaScript operators are symbols used to calculate value or in other words we can operate on operand.

Arithmetic operators (+, -, *, /) are used to calculate values and assignment operators (=, + =,% =) are used to assign values to variables.


  <script>
   var a;
   a = 5;
   document.write(a);
 </script>

JavaScript Keywords

Used to identify actions for using JavaScript keywords.

JavaScript defines a list of reserved keywords that have a specific use.

You cannot use keywords reserved by the rules as identifiers or property names.

  • Varkeyword browser variable can be understood from the following example:

 <script>
  var a, b;
  a = 2 + 2;
  b = a * 4;
  document.write(b);
 </script>

  • Hope you have understood javascript syntax using this tutorial
  • We will discuss this javascript syntax in detail in the next lecture.