Javascript: / Home / NewStyleDeclarations

New Style Variable Declarations

Strict mode is set with the text "use strict" at the beginning of the script file, script element or function. This will prevent the creation of a global variable inside a function or method when the var, let or const keyword is missing.

A variable can be created using the "let" keyword.

let myVar = "value";

This variable will belong to the function, class or method where it is defined. It will prevent you from accidently defining it again with the let, var or const keyword.

Using "let" the variable value and type can still be redefined somewhere else in the code. As in: myVar = 5;. Now the variable type is "numeric" which has a different behavior than a type of "string".

A variable can be created using the "const" keyword.

const myVar = "value";

Using "const" will prevent changing the variable value or type.

<- OldStyleDeclarations            DOMValues ->
10NewStyleDeclarations