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
  // creat a variable
  var a, b, c;
  // use variable
  a = 5;
  b = 6;
  var c = a + b;
  document.getElementById("example").innerHTML = c;
  • 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.

  // This is an example of a single line comment

  /* this example
      is multi line
        comment */


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

    var a;
    a = 6;

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.

   var a;
   a = 5;

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:

  var a, b;
  a = 2 + 2;
  b = a * 4;

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