background effect
Foreground
Foreground
D0Z - motion / graphic / dev๐Ÿงบ
JavaScript Variableโœ•

brain

Some files are private or not ready yet, if a link gives you a 404 that's why :)
This is a work in progress, new notes will be added daily

List of note Indexes

    
                .... |\| .|||.    |\/|  .|\\. .|.
              .\\||/|.  .\|..||  .\|..|||...||.....
            .|   .....||.|\\\\\\    ... |\\\/. .\\. .||
        .\\|   .|\\|..|\\ .\\\\  .\\|. .\\\\\|  |\| |\\|
        |\\  |\\|..  /\\\. |\|\\   \\\\|.   .|\\. .\\\\|
        .\\. |\\\\\\\|.. .\\|      .\\||\\/|. |\\|     .|/\|
      \. .\\\||/\|....   \\| |\/   |\\\  |\\\| .\\|  \\| ....
    |\/  |\\| |\\\\\\\| |\|.\\\   \\\\. |\\\\| |\\  \\.  ||..
      ..|||\|  .. .\\\\. |\\\\\\  .\\|....|\\\. |\\\\\\  |/. |/
    \\\|..   .\\\ |\\. .\\\| \\|   |||\\\.  ...|\\/||.  .\\\
  |\|  |\/.  /\\\\\| .\\\\. \\.   .../|.   .|\\\|.   |\\\|  |\\
    .  |||\\|.  ..||| .\\|.  |\|  \\|..../\\| |\\|  .\\\\\   ..
    \\|  .||\|.|..      |\\\|./\  \\||\. ||...    .\\\\/.  |\/||
    ..|/||.   |\\\\\|.     .|/\|  ||.        .||\\\     .|||. |\
  .\/|  \\\. .|\\\|||\\\||..       .|\\\\\\\|\\\\.  /\\\\||. |
    .|| |\\\\|  .......|\\\\\\.  .\\\. ..|||....  .\\\\|.. ...
    \\||....|\\\\\\\\||\\\\\\\/   |\|....|||\\\\\\\/....|\\\|
      ||.|\||\\| .....|\\\\..\\|    .|\\\. ||........ .|\|...
          . |\  /\\/\\\\\\. |\.  .\\\\\\.  ./\\\\/  |\\\||.
        .|\.|\| .|\|... ..              ./\\|..|\\|  ..
            .|\\|  .\\\\.\\\\\\\   \||...\\\|..|\\\|.||
                |\. ..||....||     ... ..||\\\. .|.
                        ...            .......

  

โ†‘ JavaScript


JavaScript - Variables

  • Variables are named using the ๐Ÿ”’ camelCase convention
  • Since JavaScript is built around objects, variables can hold anything
var x = 32 // mutable (scoped to function)
let x = 32 // mutable (scoped to block)
const x = 32 // immutable (scoped to block)
javascript

Declaration chaining is not recommended for readability

var x = 4,
  y = 5
javascript

Var vs Let vs Const

  • var is function scoped or globally scoped and mutable
  • let is block scoped and mutable
  • const is block scoped and immutable
function func() {
  var x = 'hello'
  let y = 'world'
  console.log(x, y) // hello world

  {
    var w = 'hello'
    let z = 'world'
    console.log(w, z) // hello world
  }
  console.log(w) // hello
  console.log(z) // ReferenceError: z is not defined
}
javascript
var x = 1
{
  var x = 2
}
console.log(x) // 2

let x = 1
{
  let x = 2
}
console.log(x) // 1

const c = 1
{
  const c = 2
}
console.log(c) // 1;
javascript

Scope

Since var and let are mutable this can lead to some scope issues

var color = 'purple' // let produce the same result
console.log(color) // purple
color = 'black'
console.log(color) // black
function changeColor() {
  color = 'blue'
  // var color = 'blue' // uncomment for fix
}
console.log(color) // black
changeColor()
console.log(color) // expected: black, actual: blue ๐Ÿ—ฟ
javascript
ยฉ 2026 d0z.eu | 0.1.0-beta.41