Completion values in JavaScript (#tilPost)

Paul Irish tweeted a while back a code snippet that puzzled him (and me).
> “omg”; var x = 4;
// “omg”

> eval( `”omg”; var x = 4;` );
// “omg”

We both expected that the "return value" of this lines will be undefined. It …


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

Paul Irish tweeted a while back a code snippet that puzzled him (and me).

> "omg"; var x = 4;
// "omg"

> eval( `"omg"; var x = 4;` );
// "omg"

We both expected that the "return value" of this lines will be undefined. It turns out what we see after evaluating these lines in a JavaScript console are not return values but rather a statement completion values. If you want to dig deeper in this topic Matt Zeunert enlightened me with his article.


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2017-03-18T11:00:00+00:00) Completion values in JavaScript (#tilPost). Retrieved from https://www.scien.cx/2017/03/18/completion-values-in-javascript-tilpost/

MLA
" » Completion values in JavaScript (#tilPost)." Stefan Judis | Sciencx - Saturday March 18, 2017, https://www.scien.cx/2017/03/18/completion-values-in-javascript-tilpost/
HARVARD
Stefan Judis | Sciencx Saturday March 18, 2017 » Completion values in JavaScript (#tilPost)., viewed ,<https://www.scien.cx/2017/03/18/completion-values-in-javascript-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » Completion values in JavaScript (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2017/03/18/completion-values-in-javascript-tilpost/
CHICAGO
" » Completion values in JavaScript (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2017/03/18/completion-values-in-javascript-tilpost/
IEEE
" » Completion values in JavaScript (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2017/03/18/completion-values-in-javascript-tilpost/. [Accessed: ]
rf:citation
» Completion values in JavaScript (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2017/03/18/completion-values-in-javascript-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.