JavaScript Quiz: When Reserved Words Meet Variable Names
Description
A multiple-choice quiz question (number 13) on a clean light gray background asking 'Which of the following JavaScript statements is syntactically correct?' with four options displayed in monospace font: a) let let = 42; b) let var = 42; c) var let = 42; d) var var = 42; Each option is preceded by an unchecked checkbox. The humor lies in the absurdity of using reserved keywords as variable names - in JavaScript, 'let' is only a reserved word in strict mode, so 'var let = 42;' (option c) is syntactically valid in sloppy mode. Meanwhile 'var' is always a reserved word, so options b and d fail. Option a also fails because 'let' cannot be re-declared with 'let' in the same scope. The question exploits JavaScript's notoriously inconsistent handling of reserved words across strict and non-strict modes
Comments
25Comment deleted
The correct answer is c) var let = 42; because 'let' is only reserved in strict mode -- proving once again that JavaScript's idea of 'reserved' is more of a gentle suggestion
Javascript can suck my nuts Comment deleted
what about c++? Comment deleted
Same Comment deleted
I like those shenanigans, like when people use C or C++ define to change words :D Or like create a German C Comment deleted
It makes a lot more sense that might initially seem. JS is a giant hodge-podge of legacy apis and behaviors that keeps user-facing web together. You cannot afford breaking some poor soul's site if they incidentally used "let" as variable name. It was absolute valid syntax before "let" was introduced as a keyword. Therefore this behavior is specifically permitted to maintain backwards-compatibility. It isn't there to use in new code. And if you think about, this is good entry-level interview question to ensure that candidate understands that a large portion of JS is legacy stuff that no-one should use. As well as illustrates their reasoning ability, since it is unlikely that this piece of esoteric knowledge it readily known. Comment deleted
i hate the fact that a language meant to manipulate HTML is being used to write backend services Comment deleted
just saying "backend" feels like an understatement ive seen people train and run models in js Comment deleted
Goddaym bro. You're totally wrong here. Comment deleted
at least python calls to c yknow Comment deleted
So you think backend JS doesnt? Gotcha Comment deleted
the context is model training/inference, not backend, hope this helps Comment deleted
You still can call all the same C code from JS that you call from Python 🤷♂️ Comment deleted
I mean you can, it just depends on whether frameworks provide usable bindings Comment deleted
But it is the same with Python isn't it? Comment deleted
yes, but Python is used in ML much more commonly Comment deleted
yeah for sure, but it is still not that different. And there are, surprisingly, many bindings for ml stuff Comment deleted
not on a regular basis, if you're doing anything serious in python its a guarantee its using c in the back instead js "people" love to push and cram it anywhere and everywhere no matter what, they'd rather die than using anything else or interfacing to something else Comment deleted
probably still easier than C++ implicit cast questions Comment deleted
or understanding a 10k line header file with #define and #if Comment deleted
Literally the most iconsistent scoping known to mankind Comment deleted
the standards are a fucking joke Comment deleted
Unsigned long long for it to be u64 Comment deleted
Long double is 64+arch bits long Comment deleted
https://youtu.be/7fGB-hjc2Gc Comment deleted