new Date().toISOString();http://kangax.github.io/es5-compat-table/
function quanti() { console.log("Quanti FTW!"); }
var quanti = function () { console.log("Quanti FTW!"); }
var quanti = function quanti() { console.log("Quanti FTW!"); }
(function () { console.log("Quanti FTW!"); })();
!function () { return "FTW!"; }();
(function (quality) { console.log("Quanti is " + quality + "!"); })("the best");
(function ($) { // Do stuff with $ })(jQuery);
function overloaded(first) { console.log("Version 1!"); ) function overloaded(first, second) { console.log("Version 2!"); )
== vs ===
Comparison x == y, where x and y are values, produces true or false.
x == ToPrimitive(y): ToPrimitive means implicit valueOf call or toString if toString is defined and valueOf is not
[0] == true; //HOW IT WORKS... //convert boolean using toNumber [0] == 1; //convert object using toPrimitive //[0].valueOf() is not a primitive so use... //[0].toString() -> "0" "0" == 1; //convert string using toNumber 0 == 1; //false!
var hoisting = 10; function hoistingIsABitch() { console.log(x); var hoisting = 10; console.log(x); }
var hoisting = 10; function hoistingIsABitch() { var hoisting; console.log(x); hoisting = 10; console.log(x); }
function shoeFactory() { return { shoeSize: 48 }; }
a = b + c [1].push(a)
a = b + c[1].push(a)
var quanti = { name: "Quanti s.r.o.", employees: 25, greet: function() { console.log("Welcome to Quanti!"); } };
function Company(name, employees) { this.name = name || "No name"; var employees = employees || 0; this.greet = function() { console.log("Welcome to Quanti!"); }; this.getNumberOfEmployees = function() { return this.employees; }; } var quanti = new Company("Quanti.s.r.o.", 25);
function Company(name, employees) { this.name = name || "No name"; var employees = employees || 0; } Company.prototype = { greet: function() { console.log("Welcome to Quanti!"); }, getNumberOfEmployees: function() { return this.employees; } } var quanti = new Company("Quanti.s.r.o.", 25);
function Company(name) { this.name = name || "No name"; this.bindInput = function(input) { jQuery(input).on("keydown", function() { this.name = jQuery(input).val(); }); }; }
function Company(name) { this.name = name || "No name"; var instance = this; this.bindInput = function(input) { jQuery(input).on("keydown", function() { instance.name = jQuery(input).val(); }); }; }
var superCoolStuff = 1; setTimeout(...);
window.superCoolStuff = 1; window.setTimeout(...);
var cz.quanti.supecoolpackage = cz.quanti.supecoolpackage || {}; cz.quanti.supecoolpackage.Company = function(name) { // ... }; var quanti = new cz.quanti.supecoolpackage.Company("Quanti s.r.o.");
var cz.quanti.supecoolpackage = (function(dependency) { var package = {}; package.Company = function(name) { // ... }; package.Employee = function(company, name) { // ... }; return package; }) ()
but beware of optimizations;)