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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<link rel="stylesheet" href="css/uikit.min.css" /> | |
</head> | |
<body> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> |
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 date = new Date("2015–01–01"); | |
var region = "US"; | |
// Some were further in the code | |
if (region === "US") { | |
var date = new Date(); | |
console.log("New date", date); // We get the current date as expected | |
} | |
console.log(date); //Expecting 2015–01–01T00:00:00.000Z but we get the current date |
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 date = new Date("2015–01–01"); | |
let region = "US"; | |
// Some were further in the code | |
if (region === "US") { | |
let date = new Date(); | |
console.log("New date", date); // We get the current date as expected | |
} | |
console.log(date); //We get 2015–01–01T00:00:00.000Z as expected :) |
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 speedOfLight=299792458; //m*s-1 | |
try { | |
speedOfLight=300; // this is not true! | |
} catch(error) { | |
console.log(error); // TypeError: Assignment to constant variable. | |
// Note - error messages will vary depending on browser | |
} | |
console.log(speedOfLight); // Expected output 299792458 |
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
//ES5 | |
let doubleNumbers = [1,2,3,4,5].map(function(number) { | |
return number*2; | |
}); | |
//ES6 Arrow function | |
let doubleNumbers = [1,2,3,4,5].map((number) => { | |
return number*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
//ES6 Arrow function one-liner | |
let doubleNumbers = [1,2,3,4,5].map(number => number*2); | |
//ES6 Arrow function multiple arguments | |
handleClick((event, seconds) => { | |
event.preventDefault(); | |
displayFireworks(); | |
showAnimation(seconds); | |
}); |
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
// Old method | |
const myArray = ['apple', 'pear', 'orange', 'banana']; | |
let fruit1 = myArray[0]; | |
let fruit2 = myArray[1]; | |
let fruit3 = myArray[2]; | |
let fruit4 = myArray[3]; | |
//ES6 destructuring | |
let [fruit1, fruit2, fruit3, fruit4] = myArray; // much better isn't? |
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 firstName="Albert" | |
let lastName="Einstein" | |
let person = {firstName, lastName} | |
console.log(person.firstName); // "Albert" | |
console.log(person.lastName); // "Einstein" |
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 first = [1,2,3]; | |
let second = [4,5,6]; | |
// If we do this | |
first.push(second); | |
// We get | |
console.log(first); // [1,2,3,[4,5,6]] that is not right | |
// Using the spread operator |
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 scores = [23, 45, 56]; | |
function averageThreeScores(a, b, c) { | |
let sum = a + b + c; | |
return sum/3; | |
} | |
console.log(averageThreeScores(…scores)); // Result 41.333333… |
OlderNewer