JavaScript Variableโ
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
-
๐ PROJECTS -
๐ ART -
๐ TECHNOLOGY -
๐ SCIENCE -
๐ PHILO-PSYCHO -
๐ HISTORY -
๐ HEALTH -
๐ GAMING -
๐ KNOWLEDGE
.... |\| .|||. |\/| .|\\. .|.
.\\||/|. .\|..|| .\|..|||...||.....
.| .....||.|\\\\\\ ... |\\\/. .\\. .||
.\\| .|\\|..|\\ .\\\\ .\\|. .\\\\\| |\| |\\|
|\\ |\\|.. /\\\. |\|\\ \\\\|. .|\\. .\\\\|
.\\. |\\\\\\\|.. .\\| .\\||\\/|. |\\| .|/\|
\. .\\\||/\|.... \\| |\/ |\\\ |\\\| .\\| \\| ....
|\/ |\\| |\\\\\\\| |\|.\\\ \\\\. |\\\\| |\\ \\. ||..
..|||\| .. .\\\\. |\\\\\\ .\\|....|\\\. |\\\\\\ |/. |/
\\\|.. .\\\ |\\. .\\\| \\| |||\\\. ...|\\/||. .\\\
|\| |\/. /\\\\\| .\\\\. \\. .../|. .|\\\|. |\\\| |\\
. |||\\|. ..||| .\\|. |\| \\|..../\\| |\\| .\\\\\ ..
\\| .||\|.|.. |\\\|./\ \\||\. ||... .\\\\/. |\/||
..|/||. |\\\\\|. .|/\| ||. .||\\\ .|||. |\
.\/| \\\. .|\\\|||\\\||.. .|\\\\\\\|\\\\. /\\\\||. |
.|| |\\\\| .......|\\\\\\. .\\\. ..|||.... .\\\\|.. ...
\\||....|\\\\\\\\||\\\\\\\/ |\|....|||\\\\\\\/....|\\\|
||.|\||\\| .....|\\\\..\\| .|\\\. ||........ .|\|...
. |\ /\\/\\\\\\. |\. .\\\\\\. ./\\\\/ |\\\||.
.|\.|\| .|\|... .. ./\\|..|\\| ..
.|\\| .\\\\.\\\\\\\ \||...\\\|..|\\\|.||
|\. ..||....|| ... ..||\\\. .|.
... .......
โ 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
varis function scoped or globally scoped and mutableletis block scoped and mutableconstis 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