This file contains 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 result = addNumbers(5, 7); | |
console.log(result); // logs 12 to the console |
This file contains 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 addNumbers(num1, num2) { | |
return num1 + num2; | |
} |
This file contains 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
addNumbers(5, 7); // logs 12 to the console |
This file contains 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 addNumbers(num1, num2) { | |
console.log(num1 + num2); | |
} |
This file contains 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
myFunction(); // logs "Hello, world!" to the console |
This file contains 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("Hello, world!"); | |
} |
This file contains 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 globalVariable = "I am global"; | |
function myFunction() { | |
let localVariable = "I am local"; | |
console.log(globalVariable); // "I am global" | |
console.log(localVariable); // "I am local" | |
} | |
myFunction(); | |
console.log(globalVariable); // "I am global" |
This file contains 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 myVariable = 5; | |
const myConstant = "Hello"; | |
var myVar = true; |
This file contains 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 myVar = "Hello World!"; // global scope | |
function myFunction() { | |
let myVar = "Goodbye World!"; // local scope | |
console.log(myVar); // "Goodbye World!" | |
function innerFunction() { | |
console.log(myVar); // "Goodbye World!" (accesses the inner scope) | |
} | |
This file contains 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() { | |
let myVar = "Hello World!"; // local scope | |
console.log(myVar); // "Hello World!" | |
} | |
myFunction(); | |
console.log(myVar); // Throws an error: "myVar is not defined" |
NewerOlder