Skip to content

Instantly share code, notes, and snippets.

@liliakai
Last active April 7, 2017 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liliakai/85d98c3cc9d4c507ac117a6e4e10160d to your computer and use it in GitHub Desktop.
Save liliakai/85d98c3cc9d4c507ac117a6e4e10160d to your computer and use it in GitHub Desktop.
------------------
console.log((function factorial(n){return ((n > 0) ? n * factorial(n-1) : n)})(10));
------------------
console.log(0.1 + 0.2)
------------------
var zero;
console.log(typeof(1 / zero + 1 / 0))
------------------
(function(){
var a = b = 3;
})();
console.log("a defined? " + (typeof a !== 'undefined'));
console.log("b defined? " + (typeof b !== 'undefined'));
-------------------
function foo1()
{
return {
bar: "hello"
};
}
function foo2()
{
return
{
bar: "hello"
};
}
console.log(foo1());
console.log(foo2());
-------------------
(function() {
console.log(1);
setTimeout(function(){console.log(2)}, 1000);
setTimeout(function(){console.log(3)}, 0);
console.log(4);
})();
------------------
var hero = {
_name: 'John Doe',
getSecretIdentity: function (){
return this._name;
}
};
var stoleSecretIdentity = hero.getSecretIdentity;
console.log(stoleSecretIdentity());
console.log(hero.getSecretIdentity());
------------------
var arr1 = "john".split('');
var arr2 = arr1.reverse();
var arr3 = "jones".split('');
arr2.push(arr3);
console.log("array 1: length=" + arr1.length + " last=" + arr1.slice(-1));
console.log("array 2: length=" + arr2.length + " last=" + arr2.slice(-1));
------------------
var list = readHugeList();
var nextListItem = function() {
var item = list.pop();
if (item) {
//process this item
doSomething(item);
// process the next item...
nextListItem();
}
};
nextListItem();
------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment