Özgün Bal
Software Developer, Javascript Enthusiast
ES6
if(condition) {
let a = 5;
// ...
}
const numbers = [1,2,3,4];console.log([1,2,3]) // [1,2,3]
console.log(...[1,2,3]) // 1 2 3
function resting (first, ...rest) {
console.log(first, rest);
}
resting(1,2,3,4); // 1, [2,3,4]function oldStyle (a, b) {
a = a == undefined ? 3 : a;
b = b == undefined ? 4 : b;
console.log(a, b);
}
function newStyle (a = 3, b = 4) {
console.log(a, b);
}const [first, second] = [1, 2];
const obj = {
x: 4,
y: 5
};
const {x, y} = obj;const x= 5;
const y=6;
const obj = {
x,
y
};
// old way
const obj2 = {
x: x,
y: y
};const myNumber = 1;
const lyric = `You're the one
my number ${myNumber}`;const doublify = x => x * 2;
setTimeout(() => {
console.log('Time is over');
}, 100)let iterable = [10, 20, 30];
for (const value of iterable) {
console.log(value);
}
// 10
// 20
// 30var sym = Symbol( "some optional description" );
sym instanceof Symbol; // false
var symObj = Object( sym );
symObj instanceof Symbol; // true
symObj.valueOf() === sym; // true// CommonJs
var dependency = require('./dependency');
// ...
module.exports = {
something: 42
}// Es6 modules
import Dependency from './dependency';
// ...
export default { something: 42 };class Parent {
constructor(x, y){
this.x = x;
this.y = y;
}
}
class Child extends Parent {
constructor(x,y,z) {
super(x,y);
this.z = z;
}
static getNameOfClass () {
return 'Child';
}
}By Özgün Bal