Very Helpful Links on JavaScript

I wanted to know why the a Flux example used a JavasScript function declaration rather than a Function Expression, so I submitted the question.

I got back a very helpful response which resulted in two super useful article references:

  1. Function Declarations vs. Function Expressions
  2. JavaScript Scoping and Hoisting

Question 1

function foo(){
    function bar() {
        return 3;
    }
    return bar();
    function bar() {
        return 8;
    }
}
alert(foo());

Question 2

function foo(){
    var bar = function() {
        return 3;
    };
    return bar();
    var bar = function() {
        return 8;
    };
}
alert(foo());

Question 3

alert(foo());
function foo(){
    var bar = function() {
        return 3;
    };
    return bar();
    var bar = function() {
        return 8;
    };
}

Question 4

function foo(){
    return bar();
    var bar = function() {
        return 3;
    };
    var bar = function() {
        return 8;
    };
}
alert(foo());

Question 5

var foo = 1;
function bar() {
	if (!foo) {
		var foo = 10;
	}
	alert(foo);
}
bar();

Question 6

var a = 1;
function b() {
	a = 10;
	return;
	function a() {}
}
b();
alert(a);

Answers:
8, 3, 3, [Type Error: bar is not a function], 10, 1

Here’s a helpful style guide:

AirBnb JavaScript Style Guide

Here’s some helpful JavaScript debugging links: