Last active
December 14, 2015 01:19
-
-
Save nfroidure/5005563 to your computer and use it in GitHub Desktop.
Fun Javascript behavior
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
if(function test(a){console.log(a)}) { console.log(test('test')) } | |
// ReferenceError : test is not defined | |
var test; | |
if(test = (function(a){console.log(a)})) { console.log(test('test')) } | |
// test |
Dynamic unnamed function:
var foo = function (a) { console.log(a); };
foo('test'); // OK
Dynamic named function:
var foo = function test (a) { console.log(a); };
foo('test'); // OK
test('test'); // ReferenceError
console.log(foo.name); // 'test'
The, well, standard (?) function:
function test (a) { console.log(a) }
test('a'); // OK
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested in Google Chrome