JavaScript: Hoisting & Function Scope

Example of Variable & Function Hoisting. When using the var declaration it is hoisted to the top of the function. When declaring a function

JavaScript

var x = 10;
function y() {// 'function y(){}' is intepreted as 'var y = function y(){}' although it will follow Function Hoisting not just Variable Hoisting
    console.log(x); //Prints undefined because of Variable Hoisting
    var x = 20; //Creates a seperate variable to the Global x, but declaration is hoisted to the top of the function
    console.log(x); //Prints 20
}
y();
console.log(x); //Prints 10 because of Functional Scope

//THE ABOVE CODE IS HOISTED AND INTERPRETED AS THE BELOW

var x, y = function y() {
    var x; 
    console.log(x);
    x = 20; //Assignment (x is 20)
    console.log(x); //Prints 20
}; //Declaration of x is hoisted (x is undefined);
x = 10; //Assignment still occurs where we intended (x is 10)
y();
console.log(x); //The variable named x in the outer scope still contains 10

//The Differences between Varible & Function Hoisting mean that
a();//This will run successfully as 'var a = function(){}' will be hoisted above it
function a(){console.log(a);}
b();//But this will return 'undefined is not a function' as only 'var b' is hoisted above.
var b = function(){console.log(a);}