JavaScript syntax


A set of rules that define well-written JavaScript programs call the syntax of JavaScript.


  • The constants in JavaScript
    • numerical constants
    • text constants
  • Variables in JavaScrip
  • Operators
  • JavaScript expressions
  • Comments in JavaScript
[adrotate group=”5″]

The constants in JavaScript

numerical constants

Numerical constants may be written with or without decimals or exponents, for example:

  • 101
  • 1.25
  • 12000e10

 text constants

Text constants are written with quotation marks or apostrophes within:

  • “Name surname”
  • ‘Name surname’

Variables in JavaScript

Variables are used to store values. Defining a variable in JavaScript is done using the keyword “var”, for example: In the first place this code we have the keyword “var” created variable “size”, and the second line we add this variable value “123”. This code we can write this:

var size;
size = 125;

var size = 125:

Operators in JavaScript

JavaScript arithmetic operators are used to calculate the value. For example in JavaScript is possible for something like: ((2 * 5) + 10) / second
Assignment operator assigns values to variables, for example: a = 10 ;.

 JavaScript Expressions

In programming terms are whole or programming instructions. These units are in JavaScript separated by a semicolon “;”.

For example, this can be written and thus, in a single line:

a = 1+2;
b = a + 3;

a = 1+2; b = a + 3;

Comments in JavaScript

Rows with comments in JavaScript code, starting with two slashes “//”. Thus, for example row:

// Ovo je komentar

be ignored during execution of JavaScript code and we will help in understanding the code.