Add javascript section

This commit is contained in:
Wilfried OLLIVIER 2018-11-22 13:05:29 +01:00
parent 57b63507e4
commit db3e6b37db
4 changed files with 89 additions and 0 deletions

View file

@ -6,6 +6,8 @@
- [Web](./dev/web/main.md)
- [front](./dev/web/front/main.md)
- [babel and babel-preset-stage-2](./dev/web/front/babel-preset-stage-2.md)
- [js](./dev/web/javascript/.md)
- [ES6 features](./dev/web/javascript/es6.md)
- [Tools](./dev/tools/main.md)
- [Git](./dev/tools/git.md)
- [SVN](./dev/tools/svn.md)

View file

@ -0,0 +1 @@
# js

View file

@ -0,0 +1,85 @@
# Presentation of the main ES6 features
## Spread Operator
It allows an iterable to expand items in it.
```javascript
array = [1, 2];
appended = [3,4];
all = [...aray, ...appended]
console.log(all)
```
This can be usefull in some situations like this one :
```javascript
array = [1, 2, 3, 4];
console.log(Math.min(...array));
```
istead of the old syntax
```javascript
array = [1, 2, 3, 4];
console.log(Math.min.apply(null, array));
```
## Rest Operator
Represent infinite number or args in an array
```javascript
const sum = (...numbers) => {
return numbers.reduce((previous, current) => {
return previous + current;
});
};
```
## Arrow Function
Function can now be written like this
```javascript
const f = (a, b) => a + b;
console.log(f(1,2));
```
instead of
```javascript
function f(a, b) {
return a + b;
}
console.log(f(1,2));
```
## Default parameters
With arrow syntax !
```javascript
const f = (a = 10) => console.log(a);
f();
f(1);
```
## Destructuring (arrays and objects)
With arrays
```javascript
const array = [1, 2];
const [a, b] = array;
console.log(a, b)
```
or objects
```javascript
const person = { name: "Jesus", age: "33" };
const { name, age } = person;
console.log(name, age);
```

View file

@ -0,0 +1 @@
# All js stuff goes here