Variables can be declared with the 'var', 'let' or 'const' keyword.
Variables do not have an explicit data type. There are 3 primitive data types.
Variables do not have a data type until a value is assigned to it and at that point the correct data type is inferred.
The semicolon is optional when statements are followed by a line break.

var myNumber1 = 10;        // number data type 
var myNumber2 = 5.38; // number data type
var myString = "text"; // string data type
var myBoolean = false; // boolean data type

var varData = data;
var varName = "Smith";
var varAge = 26;
var isOdd = false;

Strict Mode

JavaScript is not a "strongly typed" programming language which means you can get away with not declaring your variables.

var1 = 10; 

In a strongly typed programming language you must declare your variables before using them AND also declare the data type of each variable.
There is an option called Strict Mode that can force you to explicitly declare a variable before it can be used.

'use strict'
let var1 = 10;

This is similar to Option Explicit found in VBA.

All On One Line

The semicolon is required when you have two or more statements on the same line.
This line creates 3 variables and assigns them values

var myObject = new Object(); myString = 'sometext'; myNumber = math.random();  

© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext