javascript

Syntax


 

JavaScript syntax is a set of rules that govern how JavaScript code must be structured to be executable. JavaScript syntax ensures that developers adhere to a standardized format when writing code, allowing the JavaScript engine to interpret and execute it accurately.

 

Some JavaScript Syntax:

 

  • Statements and Expressions: 
    A statement is a complete instruction, while an expression is a piece of code that produces a value.

 

  •  Variables:
     Variables are declared using the var, let, or const keywords which stores data values.
let myVariable = 12;
const pi = 3.14;
var myVar = 63;

 

  • Data Types:
    JavaScript supports data types like numbers, Booleans, arrays, objects etc.
let num = 13;
let str = "Welcome to JavaScript!";
let boolVar = true;

 

  • Operators:
    Operators are used to perform operations on variable’s value like *, +, -, ==, !=, &&, ||, etc.
let product = 1 * 2;
let isRight = (expr1 === expr2);

 

  • Comments:
    Comments are used to add explanatory points with the code.
     
// This is a single-line comment

/*
This is a
multi-line comment
*/