Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradoyler/9128988 to your computer and use it in GitHub Desktop.
Save bradoyler/9128988 to your computer and use it in GitHub Desktop.
JS console Lesson #1: declaring functions.
// 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'
@bradoyler
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment