This file contains hidden or 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
// template strings / template literals ES6 | |
// | |
// wrapped with back-tick character like table names in SQL | |
// Variables and expressions wrapped in ${ } | |
// Tagged Template Literals | |
const log = console.log; | |
let message = 'I\'m going to the store'; | |
let message1 = "And then he said, \"That's what she said.\""; |
This file contains hidden or 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> | |
<!-- this comment is a child of the document --> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Nodelists Versus HTMLCollections</title> | |
<meta name="viewport" content="width=device-width"> | |
<!-- This comment is a child element of the head element --> | |
</head> | |
<!-- this comment is a child of the html element --> |
This file contains hidden or 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..of loops | |
// for..of versus for..in loops | |
let supernatural = { | |
"actors":['Jared Padelecki', 'Jensen Ackles', 'Mark Sheppard', 'Misha Collins'], | |
"characters":['Sam Winchester', 'Dean Winchester', 'Crowley', 'Castiel'], | |
"seasons":12 }; | |
for( prop in supernatural){ | |
console.log( prop, typeof supernatural[prop], |
This file contains hidden or 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
// Binary Logical Operators | |
// AND && | |
// OR || | |
// creating compound if statements | |
let ingredients = ['ham', 'onion', 'tomato']; | |
let sandwichHas = function(ingredient){ | |
for(let i of ingredients){ | |
if( i == ingredient){ |
This file contains hidden or 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
//Object.assign(target, sources... ) method | |
// used to copy objects OR | |
// to merge objects | |
let obj1 = {"arms":true, "armCount":2}; | |
let obj2 = {"weapons":['missle launcher', 'reciprocating saw']}; | |
let obj3 = {"canMove":true, "legs":0, "treads":2}; | |
let arms = Object.assign({'hasHands':true, "arms": false}, obj1); | |
console.log( arms ); |
This file contains hidden or 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
// Maps vs Objects | |
// ES6 Maps are a good replacement for Objects | |
// in many circumstances but not all | |
let a = {'name': 'Sherlock'}; | |
let b = {'name': 'Watson'}; | |
let people = {}; | |
people[a] = 'Detective'; // a ['object':Object] | |
people[b] = 'Doctor'; // b ['object':Object] |
This file contains hidden or 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 Map methods | |
// | |
// .get(k) .set(k, v) .clear() .delete(k) .has(k) .forEach(func) | |
// .size property | |
let starWars = new Map(); | |
starWars.set('Luke', 'Mark Hamill'); | |
starWars.set('Han', 'Harrison Ford'); | |
let h = starWars.get('Han'); |
This file contains hidden or 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 init = function(){ | |
let t1, t2, div1, temp, div2, cln | |
t1 = document.getElementById('target1'); | |
t2 = document.getElementById('target2'); | |
div1 = document.querySelector('.advertisement'); | |
//for(let i=0; i<5; i++){ | |
t1.appendChild(div1.cloneNode(true) ); | |
//} | |
This file contains hidden or 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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>CloneNode Method</title> | |
<meta name="viewport" content="width=device-width"> | |
<style> | |
.advertisement{ | |
color: #666; | |
padding: 1rem 2rem; |
This file contains hidden or 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
//Copy this to JSLint.com to practice using the tool | |
let people = [ | |
{"id":123, "name":"Rick Deckard", "email":"[email protected]"}, | |
{"id":456, "name":"Roy Batty", "email":"[email protected]"}, | |
{"id":789, "name":"J.F. Sebastian", "email":"[email protected]"}, | |
{"id":258, "name":"Pris", "email":"[email protected]"} | |
]; | |
//Two step version |