Skip to content

Instantly share code, notes, and snippets.

const people = [{
"id": 1,
"first_name": "Katleen",
"last_name": "Josefs",
"email": "[email protected]",
"gender": "Female",
"ip_address": "68.36.229.0"
}, {
"id": 2,
"first_name": "Cletus",
@chrislaughlin
chrislaughlin / nyan.js
Created June 6, 2017 20:30
Nyan Cat Console
//define colors
var c = {
db: "#036", //darkblue
bk: "#000", //black
rd: "#F00", //red
tn: "#FC9", //tan
lp: "#F9F", //lightpink
dp: "#F39", //darkpink
og: "#F90", //orange
@chrislaughlin
chrislaughlin / stringReplace.js
Created January 2, 2017 22:54
String Replace
const myString = "This string has many spaces";
console.log(myString.replace(/ /,""));
//"Thisstring has many spaces"
console.log(myString.replace(/ /g,""));
//"Thisstringhasmanyspaces"
@chrislaughlin
chrislaughlin / objectEqualityAssignment.js
Created January 2, 2017 22:38
objectEqualityAssignment
const chris1 = {
name: 'Chris',
location: 'Belfast'
}
const chris2 = {
name: 'Chris',
location: 'Belfast'
}
@chrislaughlin
chrislaughlin / objectEquality.js
Created January 2, 2017 22:28
Object Equality
const chris1 = {
name: 'Chris',
location: 'Belfast'
}
const chris2 = {
name: 'Chris',
location: 'Belfast'
}
@chrislaughlin
chrislaughlin / functionScopeEs6.js
Created January 2, 2017 22:15
functionScopeES6
for (var i = 0; i < 5; i++) {
setTimeout(console.log.bind(this, i), 1000);
}
@chrislaughlin
chrislaughlin / functionScope.js
Created January 2, 2017 22:11
function scope
for (var i = 0; i < 5; i++) {
setTimeout(function () {
console.log(i);
}, 1000);
}
@chrislaughlin
chrislaughlin / window.event.js
Created January 2, 2017 21:56
Window.event
onClick: () => {
console.log(Window.event);
}
//Bad
onClick: (event) => {
console.log(event);
}
//Good
@chrislaughlin
chrislaughlin / thises6.js
Created January 2, 2017 21:45
ES6 This context
this.foo = 'foo';
document.querySelector('.my-div').onclick = () => {
console.log(this.foo)
}
@chrislaughlin
chrislaughlin / this.js
Last active January 2, 2017 21:45
"this" mistakes
this.foo = 'foo';
document.querySelector('.my-div').onclick = function() {
console.log(this.foo)
}
//Logs undefined
document.querySelector('.my-div').onclick = function() {
console.log(this.foo)
}.bind(thid);