Skip to content

Instantly share code, notes, and snippets.

@markhibberd
Created October 3, 2013 22:42
Show Gist options
  • Save markhibberd/6818249 to your computer and use it in GitHub Desktop.
Save markhibberd/6818249 to your computer and use it in GitHub Desktop.
> var name = function() {}
> typeof name
"string"
> var namex = function() {}
> typeof namex
"function"
@DamonOehlman
Copy link

Interestingly, this bizarre behaviour seems to be limited only to Chrome. I think it comes down to the fact that your function declaration is coerced into window.name.

Stupid window globals :/

@jaredwy
Copy link

jaredwy commented Oct 3, 2013

Yup. As far as i know (and mdn just backed me up) name is not a standard so its going to come down to what the write status for that property is when chrome creates it. So you can't even rely on that behaviour :D

@max-mapper
Copy link

JavaScript commandment #3: Globals are literally the devil

@jaredwy
Copy link

jaredwy commented Oct 3, 2013

s/javascript/* programming language

@techtangents
Copy link

Looks like executing any javascript in global scope is bad. As soon as you're in function scope, it's fine:

> var name=function(){}; console.log(typeof name);
string
> (function() { var name=function(){}; console.log(typeof name); })();
function

@techtangents
Copy link

Looks like executing any javascript in global scope is bad.

Actually, I think this generalises to:

Javascript is bad.

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