Skip to content

Instantly share code, notes, and snippets.

@merianos
Last active September 21, 2016 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merianos/8201c1bcedb957aa3ff11af5641602cf to your computer and use it in GitHub Desktop.
Save merianos/8201c1bcedb957aa3ff11af5641602cf to your computer and use it in GitHub Desktop.
const add = (a, b) => {
return a + b;
};
// Χωρίς συνάρτηση βέλους
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 );
const eight = () => 3 + 5;
const person = {
firstName: "Νίκος",
sayName: () => {
return this.firstName;
}
}
console.log(person.sayName()); // undefined
const person = {
firstName: "Νίκος",
sayName: function() {
return this.firstName;
}
}
console.log(person.sayName()); // "Νίκος"
const person = {
firstName: 'Νίκου',
hobbies: ['Μουσική', 'Προγραμματισμό', 'Επιστήμες'],
showHobbies: function() {
this.hobbies.forEach(function(hobby) {
console.log(`Ο ${this.firstName} κάνει ${hobby}`);
});
}
};
person.showHobbies();
const person = {
firstName: 'Νίκος',
hobbies: ['Μουσική', 'Προγραμματισμός', 'Επιστήμες'],
showHobbies: function() {
this.hobbies.forEach(hobby => {
console.log(`Ο ${this.firstName} κάνει ${hobby}`);
});
}
};
person.showHobbies();
let name = `Νίκος`;
let job = `Full Stack WordPress Developer`;
const person = {
name: 'Νίκος'
};
person.name = 'Βασίλης';
console.log(person); // {name: 'Βασίλης'}
const person = 'Νίκος';
person = 'Βασίλης'; // Uncaught TypeError: Assignment to constant variable.
console.log(person);
let name = "Νίκος";
let job = 'Full Stack WordPress Developer';
for (var i = 0; i < 10; i++) {
console.log(i);
}
console.log(i); // Θα τυπώσει στην κονσόλα τον αριθμό 10;
{
let user = "Νίκος";
}
console.log(user); // Uncaught ReferenceError: user is not defined
for (let i = 0; i < 10; i++) {
console.log(i);
}
console.log(i); // Uncaught ReferenceError: i is not defined
const person = {
name: 'Νίκος',
job: 'Full Stack WordPress Developer'
};
const markup = `
<div>
<h2>${person.name}</h2>
<h3>${person.job}</h3>
</div>
`;
const multi = `This is a
multiline string`;
console.log(multi);
const multi = "This is a
multiline string";
console.log(multi);
const multi = "Αυτό είναι ένα \n κείμενο πολλαπλών γραμμών";
console.log(multi);
const add = function() {
const numbers = Array.prototype.slice.call(arguments);
return numbers.reduce((a,b) => a + b);
};
add(2, 3, 4, 5, 6, 7);
const multi = (multiplier, ...numbers) => {
return numbers.map(n => n * multiplier);
}
const add = function(...numbers) {
return numbers.reduce((a, b) => a + b);
};
add(2, 3, 4, 5, 6, 7);
const add = (a, b) => a + b;
const numbers = [39, 25, 90, 123];
const max = Math.max.apply(null, numbers);
console.log(max); // 123
const numbers = [39, 25, 90, 123];
const max = Math.max(numbers);
console.log(max); // NaN
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]
const numbers = [39, 25, 90, 123];
const max = Math.max(...numbers);
console.log(max); // 123
'use strict';
let name = "Νίκος";
let job = "Full Stack WordPress Developer";
let sentence = "Ο " name + " είναι " + job;
console.log(sentence); // "Ο Νίκος είναι Full Stack WordPress Developer"
const price = 9.99;
const shipping = 3.99;
const message = `Το σύνολο μαζί με τα μεταφορικά θα είναι ${price + shipping}.`;
console.log(message); // Το σύνολο μαζί με τα μεταφορικά θα είναι be 13.98.
let name = `Νίκος`;
let job = `Full Stack WordPress Developer`;
let sentence = `Ο ${name} είναι ${job}`;
console.log(sentence); // "Ο Νίκος είναι Full Stack WordPress Developer"
const price = 9.99;
const shipping = 3.99;
const message = `Το σύνολο μαζί με τα μεταφορικά θα είναι ${price + shipping}.`;
console.log(message); // Το σύνολο μαζί με τα μεταφορικά θα είναι 13.98.
{
var user = "Νίκος";
}
console.log(user); // Νίκος
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment