Javascript
/
Fundamentals
- 1 Fundamentals 11
-
Hello World
-
Code structure
-
Use strict
-
Variables
-
Data types
-
Type conversions
-
Maths
-
Comparitions
-
Conditional
-
Loops
-
Functions
- 2 Testing 2
-
Mocha
-
Nested describe
- 3 Objects 4
-
Basics
-
Reference
-
Methods
-
Constructor
- 4 Types 5
-
Primitives
-
Numbers
-
Strings
-
Arrays
-
Json
- 5 Classes 3
-
Constructor
-
Binding
-
Inheritance
/
Variables
➟
➟
Last update: 11-01-2022
Let
To create a variable in JavaScript, use the let keyword.
/**
* To create a variable in JavaScript, use the let keyword.
* We can combine the variable declaration and assignment ...
* into a single line.
*
* For the sake of better readability, is better to ...
* use a single line per variable.
*/
let name;
let message = "Hello World";
console.log(name); // undefined
console.log(message); // Hello World
let a = 1, b = 2; // not recommended
Var
Variables, declared with var are visible through blocks.
/**
* In older scripts you find var keyword ...
* when variable were declared.
*
* Var has no block scope, and generally not used ...
* in modern scripts.
*/
{
var a = 1; // global
}
console.log(a); // 1
{
let b = 2;
}
console.log(b); // ReferenceError: b is not defined
Const
To declare a constant, we use const instead of let.
/**
* To declare a constant, we use const instead of let.
* Such constants are named using capital letters and underscores.
*/
const COLOR_BLUE = "#00F";
const COLOR_ORANGE = "#FF7F00";
let color = COLOR_ORANGE;
console.log(color); // #FF7F00
➥ Questions github Fundamentals