Skip to content

Instantly share code, notes, and snippets.

@questsin
Created February 20, 2019 15:00
Show Gist options
  • Save questsin/3e22fd2a130564f623ab5cc411c1fcf7 to your computer and use it in GitHub Desktop.
Save questsin/3e22fd2a130564f623ab5cc411c1fcf7 to your computer and use it in GitHub Desktop.
// primitives
var a = 5;
var b = a;
b = 6;
//a; // will be 5
//b; // will be 6
// complex
var a = ['hello', 'world'];
var b = a;
b[0] = 'bye';
//a[0]; // will be 'bye'
//b[0]; // will be 'bye'
setTimeout(function() {
console.log('first or second');
}, 500);
console.log('we will see');
var a = function a () {
//'function' == typeof a; // true
};
function Person (name) {
this.name = name;
}
Person.prototype.talk = function () {
console.log('my name is', this.name);
};
//When a function throws an error, execution stops:
function t1 () {
throw new Error('hi');
//console.log('hi'); // this will never execute
}
function t2 () {
var a = 5;
try {
a();
} catch (e) {
//e instanceof Error; // true
}
console.log('you got here!');
}
for (var i = 0; i < 10; i++) {
if (object.hasOwnProperty(variable)) {
//do something
}
}
do {
} while (true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment