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
// single quotes over double quotes | |
// variables | |
var a, b, c; | |
var a = 'a', | |
b = 'b', | |
c = 'c'; |
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
function Car (doors, fuel, color) { | |
this.doors = doors; | |
this.color = color; | |
this.fuel = fuel; | |
this.changeFuel = function () { | |
if (this.fuel === 'petrol') { | |
this.fuel = 'diesel'; | |
} else { |
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
Car = { | |
doors: 0, | |
fuel: '', | |
color: '', | |
changeFuel: function (fuel) { | |
fuel === 'petrol' ? Car.fuel = 'petrol' : Car.fuel = 'diesel'; | |
} | |
}; | |
Car.changeColor = function (color) { |
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
1 == '1'; // true | |
1 === '1'; // false | |
1 === 1; //true |
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
// no caching of iteration size | |
for (var i=0; i<myArray.length; i++) {} | |
// caching of iteration size - ugly version | |
var length = myArray.length; | |
for (var i=0; i<length; i++) {} | |
// caching of iteration size - nice version | |
for (var i=0, len=myArray.length, i< len; i++) {} |
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
// returns 9 | |
parseInt('09', 10); | |
// returns 0! | |
parseInt('09'); |
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 arr = [1,2], i=0, len=arr.length; | |
for (; i<len; i++) { | |
console.log('printing: ' + arr[i]); | |
} |
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
[1,2].forEach(function (a, b, c) { | |
console.log('printing: ' + a); | |
}); |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
OlderNewer