JAVASCRIPT

  minte9
REMEMBERS




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
Data types
        A B C D E F
🔔
1/3