Lesson 3 - JavaScript ES6
Lesson 3 - JavaScript ES6
function hello()
const hello = () => {
{
return "Hello World!";
return "Hello World!";
}
}
Arrow Functions
Example:
Before With arrow functions
const is a variable that once it has been created, its value can never change.
ES6 Array Methods(map)
The .map() method allows you to run a function on each item in the array,
returning a new array as the result.
In React, map() can be used to generate lists.
Example:
{const myArray = ['apple', 'banana', 'orange'];
myArray.map((item) => console.log(item));
ES6 Array Methods(filter)
• The JavaScript Array filter() Method is used to create a new array
from a given array consisting of only those elements from the given
array which satisfy a condition set by the argument method.
ES6 Array Methods(filter)
// JavaScript to illustrate findIndex() method
function canVote(age) {
return age >= 18;
}
function func() {
var filtered = [24, 33, 16, 40].filter(canVote);
console.log(filtered);
}
func();
React ES6 Destructuring
Destructuring is a convenient way of creating new variables by extracting some
values from data stored in objects or arrays.
document.getElementById("demo").innerHTML = message;
}
ES6 Spread Operator
The JavaScript spread operator (...) allows us to quickly copy all or part of an
existing array or object into another array or object.
Example:
const marks1 = [1, 2, 3];
const marks2 = [4, 5, 6];
const marks = [...marks1, ...marks2];
console.log(marks);
ES6 Modules
JavaScript modules allow you to break up your code into separate files.
ES Modules rely on the import and export statements.
Syntax:
condition ? <expression if true> : <expression if false>