Skip to content

Instantly share code, notes, and snippets.

View prof3ssorSt3v3's full-sized avatar
🎯
Focusing

Steve Griffith prof3ssorSt3v3

🎯
Focusing
View GitHub Profile
// 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.\"";
<!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 -->
// 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],
// 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){
//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 );
// 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]
// 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');
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) );
//}
<!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;
//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