100% found this document useful (1 vote)
261 views

ES6 Notes

1. ES6 introduces new variables declarations like let and const. let variables are block scoped while const variables cannot be reassigned. 2. Arrow functions provide a concise syntax for writing anonymous functions. They are useful for callback functions. 3. Default parameters allow defining default values for parameters if they are not passed to the function. This summarizes some of the key features introduced in ES6 including new variable declarations, arrow functions, default parameters and more.

Uploaded by

Nichita Domide
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
261 views

ES6 Notes

1. ES6 introduces new variables declarations like let and const. let variables are block scoped while const variables cannot be reassigned. 2. Arrow functions provide a concise syntax for writing anonymous functions. They are useful for callback functions. 3. Default parameters allow defining default values for parameters if they are not passed to the function. This summarizes some of the key features introduced in ES6 including new variable declarations, arrow functions, default parameters and more.

Uploaded by

Nichita Domide
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

ES6 stuff :

1. New Let and Const variables

- Variables declared with -var- are declared globally, or local if


declared insinde a function

- Variables declared with -let- are limited to the scope of the function
where they were declared

- The value of const variables can't be changed, so basicly they are


Read-only

- You can mutate an array declared as const

- To prevent data mutation, we can use Object.freeze

2. Arrow function

- When you have an anonimus function, you can convert it to an arrow


function

- Syntax : (parameters) => { stuff to do } ;

- If you only have one argument, you don't need to use paranthases,
and if you only have one line of code for the function instructions,
you don't need the {} or the return keyword

- You can also use them as callback function

3. Default parameters

- You can set a default parameter in case that it isn't passed to the
functinon

- Syntax : function increment (number, value = 1) {...}

4. Rest operator

- The rest operator lets you create a function, that takes any number of
arguments

- Syntax : function sum(...) {} // Now I can call this function with any
number of arguments

5. Spread operator

- It expands or spreads out an array

- You can only use it in an argument to a function, or in an array literal

- You can use it to copy an array to another array, in order to transfer the
content, not the reffrence
- Example : arr2 = [...arr1]

6. Destructuring

- It is a special syntax used to asign values to a variable, taken directly


from an Object

- Example : var voxel - {x: 3.6, y: 7.4, z: 6.5 };


const { x: a, y: b, z: c } = voxel;

- You can also use destructuring to asssign variables values from nested
objects

- In this example, we create three variables a, b, c, and we asign them the


values of x, y, z

- Or to assign variables values from an array, ex : const[z, x] = [1, 2, 3,


4, 5];

- You can use it together with the rest operator, to reassign array
elements, ex: const[ , , ...arr] = oldArray;

- You can use it to pass an Obj as a function's paramaters

7. Template literals

- Ex : `Hello, my name is ${name}`;

- You can make multi-line strings, just by writnig it on more lines

8. Classes and subclasses

- Same as in Java

- Constructor keyword

- Get and Set keywords

9. Import and export

- You can use the import and export keywords, to share data between files

- You can use * to import everything

10. For of loop : for(let number of array) {}

11. Promises

- Syntax : async function getTop100() {


const response = await fetch(apiUrl);
const json = await response.json();
}

You might also like