Skip to content

Instantly share code, notes, and snippets.

@jacopotarantino
Created March 5, 2018 18:47
Show Gist options
  • Save jacopotarantino/cbe310d0042527cddc497ce9c709e7a3 to your computer and use it in GitHub Desktop.
Save jacopotarantino/cbe310d0042527cddc497ce9c709e7a3 to your computer and use it in GitHub Desktop.
Impossible JavaScript Question
/* what do each of these statements return?
(assume that they are evaluated individually but in order.)
*/
const foo = 'asdf'; //=> ?
foo.bar = 12345; //=> ?
foo; //=> ?
foo.bar; //=> ?
Object.getOwnPropertyNames(foo); //=> ?
@EionRobb
Copy link

EionRobb commented Mar 6, 2018

I didn't realise the second one behaved differently without strict mode. Are we assuming non-strict?

@mgd020
Copy link

mgd020 commented Mar 6, 2018

What's the use of knowing this? You wouldn't do it in production so who cares?

@jacopotarantino
Copy link
Author

@EionRobb - I hadn't even thought about strict mode yet. Good catch!
@mgd020 - Shits and giggles lol. This actually came up because of production code so somebody did it in production.
@gkaykck - Haha. Well done ;). I absolutely don't expect people to know this stuff by heart. That's why it's such a weird challenge. This isn't stuff that you should know because you should never be doing this nonsense to begin with.

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