Skip to content

Instantly share code, notes, and snippets.

@manojsinghnegiwd
Last active November 10, 2016 19:36
Show Gist options
  • Save manojsinghnegiwd/4ed4e3776fd52483e7c6737e8f2af27c to your computer and use it in GitHub Desktop.
Save manojsinghnegiwd/4ed4e3776fd52483e7c6737e8f2af27c to your computer and use it in GitHub Desktop.
function accessArguments () {
console.log(arguments[0]);
}
accessArguments(1, 2); // this will log 1
var args = Array.prototype.slice.call(arguments);
args.slice(1, 2); // not you can use args as normal array
console.log(1 == '1'); // this will log true
var x = (function IIFE(){
return 'Hello I am IIFE';
})();
console.log(x) // will log Hello I am IIFE
var x = (function IIFE(){
return arguments[0];
})(1);
console.log(x) // will log 1
var arr = ['one', 'two', 'three', 'four', 'five', 'six'];
arr instanceof Array
console.log(1 === '1'); // this will log false
function merge () {
var args = Array.prototype.slice.call(arguments);
var obj = {};
for( var i = 0; i < args.length; i++ ) {
if(args[i] instanceof Object) {
for( var prop in args[i] ) {
obj[prop] = args[i][prop] // we append new object property and if any property exist overwrite it
}
} else {
console.error('you provided a non object at : ', i);
}
}
return obj;
}
var obj = merge( { x: 1 }, { y: 2 }, { x: 3 , y: 4} ) // will output {x: 3, y: 4}
function accessArguments () {
var x = arguments[1] || 2;
console.log(x);
}
accessArguments(1); // this will log 2
accessArguments(1, 3); // this will log 3
var x = 20;
var pass = x > 10 ? true : false
var Hurray = pass ? true : false
typeof x === 'undefined' // will return true
var x = 1;
typeof x === 'undefined' // will return false
typeof x === 'number' // will return true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment