Created
August 31, 2024 17:16
-
-
Save zachary/014a859cf455956bc2ccd4411db74536 to your computer and use it in GitHub Desktop.
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
/*** ES6 Features ***/ | |
// Let and Const | |
let variableName = "value"; // Block-scoped, can be reassigned | |
const constantName = "value"; // Block-scoped, cannot be reassigned | |
// Arrow Functions | |
const myFunction = (param) => { | |
return param * 2; | |
} | |
// Template Literals | |
const greeting = `Hello, $(name)!` // Embedded expressions | |
// Destructuring Assignment | |
const { a, b} = obj; // Extracts properties from an object | |
const [x, y] = array; // Extracts values from an array | |
// Spread and Rest Operator | |
const newArray = [...arrayl, ...array2]; // Combines arrays | |
const newObj = {...obj1, ...obj2 }; // Combines objects | |
function sum(...numbers) { | |
return numbers.reduce((acc, curr) => acc + curr, 0); // Rest parameter | |
} | |
// Default Parameters | |
function multiply(a, b = 1){ | |
return a * b; | |
} | |
// Promises | |
const promise = new Promise((resolve, reject) => { | |
if (success) { | |
resolve ("Success!"); | |
} else { | |
reject ("Failure!"); | |
} | |
}); | |
promise | |
•then ((response) => console. log(response)) | |
•catch((error) =› console. log(error)); | |
// Classes | |
class Animal { | |
constructor (name) { | |
this.name = name; | |
} | |
speak() { | |
console.log(`${this.name) makes a noise.`); | |
} | |
} | |
class Dog extends Animal { | |
speak() { | |
console. log(`${this.name) barks.`); | |
} | |
} | |
const dog = new Dog ("Rex"); | |
dog.speak(); // Rex barks. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment