Skip to content

Instantly share code, notes, and snippets.

View kgates-github's full-sized avatar

kgates-github

View GitHub Profile
@kgates-github
kgates-github / JavaScriptVariableHoisting.js
Last active December 13, 2015 16:49
When I decided to take JavaScript seriously a while back, I realized that not fully understanding how the language handles variable scope can lead to some forehead-slapping debugging sessions. In JavaScript, a variable declaration (e.g., var foo = 1) at the end of a function will execute when the function is called, and before any code within th…
var foo = 1,
test;
function barOne() {
if (!foo) var foo = 100;
return foo;
}
test = barOne();
console.log(test); // 100
@kgates-github
kgates-github / PascalsTriangles.js
Last active May 6, 2020 07:52
Two ways to create a Pascal's Triangle in JavaScript.
var numTiers = 100,
triangle,
start,
stop;
/**
*
* First version uses recursion
*
*/