Skip to content

Instantly share code, notes, and snippets.

View CodeDraken's full-sized avatar

CodeDraken

View GitHub Profile
@CodeDraken
CodeDraken / JS-Essentials-Objects.js
Created October 9, 2018 20:00
Code for JavaScript Essentials: Objects
// Wolf
// - Properties
// -- fur color
// -- eye color
// -- size
// -- gender
// -- age
// - Actions
// -- walk/run
@CodeDraken
CodeDraken / basic-abc-stack.js
Last active June 8, 2019 22:23
Demonstrating the call stack
var myOtherVar = 10
function a() {
console.log('myVar', myVar)
b()
}
function b() {
console.log('myOtherVar', myOtherVar)
c()
@CodeDraken
CodeDraken / basic-abc-stack-global.js
Created June 8, 2019 23:27
The global context so far
var myOtherVar = undefined
var myVar = undefined
function a() {...}
function b() {...}
function c() {...}
@CodeDraken
CodeDraken / basic-abc-stack-result.js
Last active June 8, 2019 23:30
what was outputted
"myVar" undefined
"myOtherVar" 10
"Hello world!"
@CodeDraken
CodeDraken / basic-abc-stack-exc1.js
Last active June 8, 2019 23:32
The first execution step
function a() {
console.log('myVar', myVar)
b()
}
@CodeDraken
CodeDraken / scope-scope-chain.js
Created June 9, 2019 13:12
Demonstrating the scope, scope chain
// scope & scope chain
function a() {
var myOtherVar = 'inside A'
b()
}
function b() {
var myVar = 'inside B'
@CodeDraken
CodeDraken / scope-scope-chain-commented.js
Last active June 9, 2019 14:40
scope and scope chain example with comments
// scope & scope chain commented
// was declared globally, outer reference is global
function a() {
// variable created inside context of a
var myOtherVar = 'inside A'
// b called inside a, but was lexically declared in the global context
b()
}
@CodeDraken
CodeDraken / loop-scope.js
Created June 9, 2019 19:49
Demonstrating block scope in a loop
function loopScope () {
var i = 50
var j = 99
for (var i = 0; i < 10; i++) {}
console.log('i =', i)
for (let j = 0; j < 10; j++) {}
@CodeDraken
CodeDraken / blockscope.js
Last active June 9, 2019 20:03
block scope example 2
// block scoping - literal blocks
function blockScope () {
let a = 5
{
const blockedVar = 'blocked'
var b = 11
a = 9000
}
@CodeDraken
CodeDraken / simple-closure.js
Last active January 20, 2020 22:46
Demonstrating a closure
// Closure Example
function exponent (x) {
// returns a new function to be called later
// this function remembers the x argument
return function (y) {
// ** is the exponentiation operator
// same thing as Math.pow() or y to the power of x
return y ** x
}