Syntax Of JavaScript – Basics Every Beginner Should Know

JavaScript syntax is the set of rules, how JavaScript programs are constructed:

// How to create variables:
var x;
let y;

// How to use variables:
x = 5;
y = 6;
let z = x + y;

Syntax Of JavaScript

JavaScript Values

The JavaScript grammar specifies two types of values:

  • Fixed values.
  • Variable Values

Fixed values are referred to as literals.
Variable values are referred to as Variables.

JavaScript Literals

The two primary syntactic rules for fixed values are:

1. Numbers can be written with or without decimals.

10.50

1001

HTML Compiler Try Yourself :

2. Strings are text enclosed between double or single quotes:

“John Doe”

‘John Doe’

HTML Compiler
Try Yourself :

JavaScript Variables

In a computer language, variables are used to store data.

To declare variables in JavaScript, use the keywords varlet and const.

The equal sign is used to assign values to variables.

In this example, x is treated as a variable. Then, x is assigned (given) the value six.

let x;
x = 6;

HTML Compiler - Variables Example
Try Yourself :

JavaScript Operators

JavaScript uses arithmetic operators ( + - * / ) to compute values:

(5 + 6) * 10
HTML Compiler - Operators Example
Try Yourself :

To assign values to variables in JavaScript, use the assignment operator= ).

let x, y;
x = 5;
y = 6;

HTML Compiler - Assignment Example
Try Yourself :

JavaScript Keywords

Actions to be taken are identified using JavaScript keywords.

The browser is instructed to create variables using the let keyword:

Reply Comments

Leave a Reply