Skip to content

Instantly share code, notes, and snippets.

@sagar-more
sagar-more / script.js
Created April 15, 2019 18:17
No Global
(function(){
var a,b;
a=b = 3;
})();
console.log("a defined? " + (typeof a !== 'undefined'));
console.log("b defined? " + (typeof b !== 'undefined'));
@sagar-more
sagar-more / script.js
Created April 15, 2019 18:07
Return statement
function foo() {
return {
bar: "hello"
};
}
console.log(foo())
@sagar-more
sagar-more / script.js
Created April 15, 2019 17:59
Sum of all numbers
var list = process.argv.slice(2);
var sum = 0;
var add = function () {
if (list.length === 0) {
console.log('sum ' + sum);
}
var item = list.pop();
var args = process.argv.slice(2);
var hero = {
name: args[0],
getSecretIdentity: function (){
return this.name;
}
};
var stoleSecretIdentity = hero.getSecretIdentity.bind(hero);
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(`<body></body>`, { runScripts: "dangerously" });
function createDom(total) {
for (let i = 0; i < total; i++) {
var btn = dom.window.document.createElement('button');
btn.appendChild(dom.window.document.createTextNode('Button ' + i));
btn.addEventListener('click', function(){ console.log(i); });