DEV Community

Cover image for [week1] Days 1 - ES6 Modules
Black-Thor
Black-Thor

Posted on • Updated on

[week1] Days 1 - ES6 Modules

So for my 100 days of code i decided to start with the basic by ending my learning courses on freecodecamp and getting the certification from FreeCodeCamp on JavaScript Algorithms and Data Structures .
I had already started the certification but i leaved it . So i started with the ES6 part , And it was a good choice , i have found some ES6 syntax i didn't know or use .

This is my top 5 thing i learned todays :

  • Rest Parameter : With the rest parameter, you can create functions that take a variable number of arguments. These arguments are stored in an array that can be accessed later from inside the function.
const sum = (...args) => {
  return args.reduce((a, b) => a + b, 0);
}
console.log(sum(1, 2, 3)); // 6
Enter fullscreen mode Exit fullscreen mode
  • Spread Operator : which allows us to expand arrays and other expressions in places where multiple parameters or elements are expected.
Math.max.apply(null, arr)

const arr = [6, 89, 3, 45];
const maximus = Math.max(...arr);
Enter fullscreen mode Exit fullscreen mode
  • Use Destructuring Assignment to Extract Values from Objects
//ES5
const user = { name: 'John Doe', age: 34 };

const name = user.name;
const age = user.age;

//ES6
const { name, age } = user;
```



- Use Destructuring Assignment to Assign Variables from Nested Objects


````javascript
//ES5
const user = {
  johnDoe: { 
    age: 34,
    email: 'johnDoe@freeCodeCamp.com'
  }
};

//ES6
//Here's how to extract the values of object properties and assign them to variables with the same name:
const { johnDoe: { age, email }} = user;
// here's how you can assign an object properties' values to variables with different names:
const { johnDoe: { age: userAge, email: userEmail }} = user;

```
{% endraw %}


- Object Literal Declarations Using Object Property Shorthand
{% raw %}

````javascript
//ES5
const getMousePosition = (x, y) => ({
  x: x,
  y: y
});
//ES6
const getMousePosition = (x, y) => ({ x, y });
```



and many more thing 
On day 2 i will work on [regex ](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/#regular-expressions)

PS:
- if you see any spelling or grammar mistakes can you notify me (I am still improving my English)  ? thank you !
- if you have any tips for improving my post feel free to comment on the post

Enter fullscreen mode Exit fullscreen mode

Top comments (0)