/typescript/

TypeScript part 18 (destructuring)

2017-03-04 16:23:03

TypeScript

const colors = ["White", "Red", "Blue"];
const [c1, c2, c3] = colors;
console.log(c1);
console.log(c2);
console.log(c3);

JavaScript

var colors = ["White", "Red", "Blue"];
var c1 = colors[0], c2 = colors[1], c3 = colors[2];
console.log(c1);
console.log(c2);
console.log(c3);

TypeScript

const person = {
    name: "Michał",
    age: 18
};

const {name, age} = person;

console.log(name, age);

JavaScript

var person = {
    name: "Michał",
    age: 18
};
var name = person.name, age = person.age;
console.log(name, age);

TypeScript

const person = {
    name: "Michał",
    age: 18
};

const {name: personName, age: personAge} = person;

console.log(personName, personAge);

JavaScript

var person = {
    name: "Michał",
    age: 18
};
var personName = person.name, personAge = person.age;
console.log(personName, personAge);