This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// let example | |
{ let variable = 3 } // Created in local scope (the current block scope) | |
console.log(variable) // ReferenceError: variable is not defined | |
// var example | |
{ var variable = 37 } // Created in global scope (the current function scope) | |
console.log(variable) // 37 | |
// const example | |
const object = {hello: "world"} // Created in local scope (the current block scope) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(let i = 0; i < 3; i++) { console.log(i) } // 0, 1, 2 | |
console.log(i) // ReferenceError: i is not defined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var variable = 37 | |
function myFunction () { | |
var variable = 40 | |
console.log(variable) // 40 | |
} | |
console.log(variable) // 37 | |
myFunction() | |
console.log(variable) // 37 | |
// Output: 37, 40, 37 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var variable = 37 | |
function myFunction () { | |
variable = 40 | |
console.log(variable) // 40 | |
} | |
console.log(variable) // 37 | |
myFunction() | |
console.log(variable) // 40 | |
// Output: 37, 40, 40 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const constant = 37 | |
console.log(constant) // 37 | |
constant += 1 // TypeError: invalid assignment to const `constant' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunction () { | |
console.log(variable) // 27 | |
variable = 40 } | |
console.log(variable) // undefined | |
variable = 27 | |
myFunction() | |
console.log(variable) // 40 | |
var variable = 37 | |
// Output: undefined, 27, 40 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunction () { | |
console.log(variable) // undefined | |
var variable = 40 } | |
console.log(variable) // undefined | |
variable = 27 | |
myFunction() | |
console.log(variable) // 27 | |
var variable = 37 | |
// Output: undefined, undefined, 27 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let variable = 37 | |
function multiplyBySomeNumber(number) { | |
return function(innerNumber) { | |
return innerNumber * number | |
} | |
} | |
// equivalent to multiplyBySomeNumber = number => innerNumber => number * innerNumber | |
const multiplyByFive = multiplyBySomeNumber(5) | |
let variableTimesFive = multiplyByFive(variable) | |
console.log(variableTimesFive) // 185 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// global var example | |
function myFunction() { | |
whoops = 3 | |
} | |
console.log(whoops) // ReferenceError: whoops is not defined | |
myFunction() | |
console.log(whoops) // 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// global var example | |
function myFunction() { | |
whoops = 3 | |
} | |
console.log(whoops) // undefined | |
myFunction() | |
console.log(whoops) // 3 | |
var whoops |