Last active
September 21, 2016 08:37
-
-
Save merianos/8201c1bcedb957aa3ff11af5641602cf to your computer and use it in GitHub Desktop.
ES6 Tutoial - Web Design Blog - http://www.web-resources.eu/archives/es6-%CF%84%CE%B9-%CE%BC%CF%80%CE%BF%CF%81%CF%8E-%CE%BD%CE%B1-%CF%87%CF%81%CE%B7%CF%83%CE%B9%CE%BC%CE%BF%CF%80%CE%BF%CE%B9%CE%AE%CF%83%CF%89-%CF%83%CE%AE%CE%BC%CE%B5%CF%81%CE%B1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const add = (a, b) => { | |
return a + b; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Χωρίς συνάρτηση βέλους | |
const numbers = [3,4,5,6,7,8]; | |
const doubleNumbers = numbers.map(function(n) { | |
return n * 2; | |
}); | |
// Με συνάρτηση βέλους | |
const numbers = [3,4,5,6,7,8]; | |
const doubleNumbers = numbers.map( n => n * 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const eight = _ => 3 + 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const eight = () => 3 + 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const add5 = a => a + 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
firstName: "Νίκος", | |
sayName: () => { | |
return this.firstName; | |
} | |
} | |
console.log(person.sayName()); // undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
firstName: "Νίκος", | |
sayName: function() { | |
return this.firstName; | |
} | |
} | |
console.log(person.sayName()); // "Νίκος" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add(2, 3); // 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
firstName: 'Νίκου', | |
hobbies: ['Μουσική', 'Προγραμματισμό', 'Επιστήμες'], | |
showHobbies: function() { | |
this.hobbies.forEach(function(hobby) { | |
console.log(`Ο ${this.firstName} κάνει ${hobby}`); | |
}); | |
} | |
}; | |
person.showHobbies(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
firstName: 'Νίκος', | |
hobbies: ['Μουσική', 'Προγραμματισμός', 'Επιστήμες'], | |
showHobbies: function() { | |
this.hobbies.forEach(hobby => { | |
console.log(`Ο ${this.firstName} κάνει ${hobby}`); | |
}); | |
} | |
}; | |
person.showHobbies(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let name = `Νίκος`; | |
let job = `Full Stack WordPress Developer`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
name: 'Νίκος' | |
}; | |
person.name = 'Βασίλης'; | |
console.log(person); // {name: 'Βασίλης'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = 'Νίκος'; | |
person = 'Βασίλης'; // Uncaught TypeError: Assignment to constant variable. | |
console.log(person); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let name = "Νίκος"; | |
let job = 'Full Stack WordPress Developer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (var i = 0; i < 10; i++) { | |
console.log(i); | |
} | |
console.log(i); // Θα τυπώσει στην κονσόλα τον αριθμό 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
let user = "Νίκος"; | |
} | |
console.log(user); // Uncaught ReferenceError: user is not defined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (let i = 0; i < 10; i++) { | |
console.log(i); | |
} | |
console.log(i); // Uncaught ReferenceError: i is not defined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
name: 'Νίκος', | |
job: 'Full Stack WordPress Developer' | |
}; | |
const markup = ` | |
<div> | |
<h2>${person.name}</h2> | |
<h3>${person.job}</h3> | |
</div> | |
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const multi = `This is a | |
multiline string`; | |
console.log(multi); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const multi = "This is a | |
multiline string"; | |
console.log(multi); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const multi = "Αυτό είναι ένα \n κείμενο πολλαπλών γραμμών"; | |
console.log(multi); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const add = function() { | |
const numbers = Array.prototype.slice.call(arguments); | |
return numbers.reduce((a,b) => a + b); | |
}; | |
add(2, 3, 4, 5, 6, 7); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const multi = (multiplier, ...numbers) => { | |
return numbers.map(n => n * multiplier); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const add = function(...numbers) { | |
return numbers.reduce((a, b) => a + b); | |
}; | |
add(2, 3, 4, 5, 6, 7); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const add = (a, b) => a + b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numbers = [39, 25, 90, 123]; | |
const max = Math.max.apply(null, numbers); | |
console.log(max); // 123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numbers = [39, 25, 90, 123]; | |
const max = Math.max(numbers); | |
console.log(max); // NaN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numbersArray1 = [3, 4, 5, 7, 8]; | |
const numbersArray2 = [9, 6, 10, 11]; | |
const concatArray = [...numbersArray1, ...numbersArray2]; | |
console.log(concatArray); // [3, 4, 5, 7, 8, 9, 6, 10, 11] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numbers = [39, 25, 90, 123]; | |
const max = Math.max(...numbers); | |
console.log(max); // 123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
...numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let name = "Νίκος"; | |
let job = "Full Stack WordPress Developer"; | |
let sentence = "Ο " name + " είναι " + job; | |
console.log(sentence); // "Ο Νίκος είναι Full Stack WordPress Developer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const price = 9.99; | |
const shipping = 3.99; | |
const message = `Το σύνολο μαζί με τα μεταφορικά θα είναι ${price + shipping}.`; | |
console.log(message); // Το σύνολο μαζί με τα μεταφορικά θα είναι be 13.98. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let name = `Νίκος`; | |
let job = `Full Stack WordPress Developer`; | |
let sentence = `Ο ${name} είναι ${job}`; | |
console.log(sentence); // "Ο Νίκος είναι Full Stack WordPress Developer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const price = 9.99; | |
const shipping = 3.99; | |
const message = `Το σύνολο μαζί με τα μεταφορικά θα είναι ${price + shipping}.`; | |
console.log(message); // Το σύνολο μαζί με τα μεταφορικά θα είναι 13.98. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
var user = "Νίκος"; | |
} | |
console.log(user); // Νίκος |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment