Last active
August 29, 2015 13:56
-
-
Save bradoyler/9128988 to your computer and use it in GitHub Desktop.
JS console Lesson #1: declaring functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. declare a "named" function | |
function myNamedFunction(){ return true; } | |
// assertions | |
console.log(typeof window.myNamedFunction === "function"); // true | |
console.log(myNamedFunction.name === "myNamedFunction"); // true | |
// 2. declare anonymous function | |
var myAnonymousFunction = function(){ return true; }; | |
//assertions | |
console.log(typeof window.myAnonymousFunction === "function"); // true | |
console.log(myAnonymousFunction.name === ""); // true | |
// 3. another way to declare | |
window.anotherAnonFunc = function(){ return true; } | |
console.log(typeof window.anotherAnonFunc === "function"); // true | |
// 4. shows how to reference a func before it's declared | |
function outerFunc(){ | |
console.log(typeof innerFunc === "function"); // true (that's right) | |
function innerFunc(){} | |
console.log(window.innerFunc === undefined); // true : not a global function | |
} | |
outerFunc(); | |
// 5. shows difference between function "name" and variable name. | |
var funcA = function funcB() { } | |
console.log(funcA.name); // 'funcB' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The idea for this course is that you can copy/paste this gist into your browser console and play around with the assertions. Which will hopefully help you better understand how javascript works.
Feedback greatly appreciated.