Typing
JS is dynamically typed
-
The program find the type itself, not indicated by the user.
-
const a = 5; //a is a number
const b = 4.12; // b is a number
const c = "some string"; //string
const d = [7,4,5,2]; // array
Types are adapted dynamically
let a = 5; //a is a number
a = "bear"; // now a is a string
const b = [4,"a string",[7,8]];
The same variable can contain various types at different part of the code
Good practice
-
- Avoid it! Hard to read.
-
- One variable = one type in only one context.
38/41