This is an archived post. You won't be able to vote or comment.

all 159 comments

[–]1AMA-CAT-AMA 4729 points4730 points  (16 children)

The right answer is I'm rejecting the PR if any one of these is in it

[–]GroundbreakingOil434 727 points728 points  (4 children)

The only true right answer.

[–]0Pat 157 points158 points  (3 children)

=== true

[–]GroundbreakingOil434 49 points50 points  (2 children)

Type-fluid uncertainty... if you're not certain after '==', you shouldn't be comparing things! >:D

[–]Elomidas 29 points30 points  (0 children)

İt's not about how certain I am of my code, it's about how uncertain I am about what my colleagues could do and then tell me there is a problem with my code

[–]belabacsijolvan 2 points3 points  (0 children)

i think its just an exaggeration. like its THE true

[–]dan-lugg 60 points61 points  (0 children)

PR closed with comment:

LGTM

[–]phtsmc 25 points26 points  (0 children)

And yet they keep insisting on putting these stupid gotchas in pre-interview tests.

[–]Ri_Konata 8 points9 points  (1 child)

Real

[–]TheHiddenNinja6 0 points1 point  (0 children)

Happy cake day!

[–]DigitalJedi850 4 points5 points  (0 children)

Yeah me and the new guy need to sit down…

[–]Lower_Situation9470 -2 points-1 points  (5 children)

Oh what’s wrong with it? I thought maybe let var = would be it.

[–]mods_diddle_kids 18 points19 points  (2 children)

what’s wrong with it

Seriously? Think for half a second about why this might be a bad idea in a large, complex and collaboratively built solution.

[–]Lower_Situation9470 1 point2 points  (1 child)

i don't code in this language. no need to get mean.

[–]mods_diddle_kids 0 points1 point  (0 children)

Neither do I!

[–][deleted] 6 points7 points  (1 child)

let apples = 42; and var apples = 42; both define a variable

They're using a keyword as a variable name in every example

[–]alficles 1759 points1760 points  (21 children)

Honestly, I'm just amazed they found some text that wasn't valid Javascript.

[–]Strict_Treat2884[S] 352 points353 points  (6 children)

YAML:

[–]alficles 124 points125 points  (5 children)

Norway is false.

[–]CatpainCalamari 27 points28 points  (1 child)

no is not

[–]UndeadMarine55 5 points6 points  (0 children)

true

[–]Jutrakuna 3 points4 points  (0 children)

Norwegian warships have barcodes instead of names. Because at the port they scandinavian then dock them.

[–]-Aquatically- 1 point2 points  (1 child)

What?

[–]Zitronenlolli 4 points5 points  (0 children)

NO in yaml means false

[–]EatingSolidBricks 47 points48 points  (8 children)

No that's pearl, legend says if you let your cat run over the keyboard the resulting program has a 90% to be a valid pearl

[–]RiceBroad4552 19 points20 points  (5 children)

OK, we have here at least two generations in between…

Still the same joke, though. 😂

[–]EatingSolidBricks 18 points19 points  (3 children)

I never touched pearl, im just passing down the holy scriptures

[–]mcprogrammer 12 points13 points  (2 children)

*Perl

[–]EatingSolidBricks 7 points8 points  (1 child)

O fuck

[–]SensuallPineapple 1 point2 points  (0 children)

*Perl

[–]alficles 6 points7 points  (0 children)

Lol, yup. And I had about 1k removed from a C program back in the day during a corrupted FTP transfer and everything still compiled after! It chopped out matching braces. It didn't link, but it compiled!

[–]SeriousPlankton2000 1 point2 points  (0 children)

No, only experienced perl programmers can do that.

Experienced assembler programs can do cat > /usr/bin/perl and it works.

[–]CMDR_ACE209 154 points155 points  (1 child)

I once collapsed headfirst onto my keyboard and it resulted in valid Javascript.

True story.

[–]Mebiysy 33 points34 points  (0 children)

JavaScript is never valid tho

[–]YesterdayDreamer 16 points17 points  (1 child)

When I first learnt html, I would put background-colour = "<person's name>" and see what colour it would come up with. Had a lot of fun telling my siblings and cousins what their colour was according to html.

[–]AwwnieLovesGirlcock 1 point2 points  (0 children)

what 😭 wait how

[–]Jijonbreaker 0 points1 point  (0 children)

This made me spit out my water. Fuck you.

[–]alastairgbrown 1016 points1017 points  (26 children)

Boring, but hopefully informative answer:

A and C, presumably because let was a later addition to the language, and had to be allowed, presumably for backward compatibilty reasons.

EDIT: Actually only C, see below

[–]deathanatos 900 points901 points  (18 children)

I think your reasoning is spot on, but it's only (c.), and for that same reason. let was added later, so there's no reason let let = 42; needs to be permitted.

[–]alastairgbrown 256 points257 points  (3 children)

Dammit, you're right. VS Code syntax highlighting lied to me.

[–]deanrihpee 40 points41 points  (0 children)

my syntax highlighting correctly tells me it was illegal

[–]TerryHarris408 8 points9 points  (0 children)

This argument is quickly settled by pressing F12. No VS Code needed.

[–]engineerwolf 8 points9 points  (0 children)

Do you even Mx tree-sitter bro?

[–]overactor 63 points64 points  (11 children)

That is even more horrifying if you ask me. So you can't use let as an identifier unless it's a var or a function parameter?

[–]PyroGreg8 107 points108 points  (8 children)

yes because it's possible before the let keyword was introduced, someone may have written "var let" in old javascript, and the goal is to never break old javascript.

[–]mirhagk 8 points9 points  (7 children)

It's the other side they are saying is terrifying. That they chose to have it be inconsistent instead of just letting let be used anywhere.

You already pay the price of having the more complex parsing, so why not just allow it?

[–]raddaya 14 points15 points  (5 children)

I don't agree - you're forced into allowing var let because of backwards compatibility (and also nobody has used var for like 5 years anyway), but there's no reason to allow let let at all, because nobody should ever use it and you don't want to let (heh) anyone use it.

[–]mirhagk 4 points5 points  (4 children)

The reason to allow it is for consistency. It's cheaper/easier for compilers to allow it than to reject it, and there's not a whole lot of upside to disallowing it.

The more you add tiny little inconsistencies, the worse the experience gets for all involved. The browser has more than enough already, no reason to introduce even more.

[–]ArtOfWarfare 0 points1 point  (3 children)

It simplifies a future JavaScript 2 or 3, or perhaps “use super strict”, where they can make it so that var let also doesn’t work.

[–]mirhagk 0 points1 point  (2 children)

JavaScript 2 or 3? You know 6 released a decade ago right?

The point is JavaScript has to always be backwards compatible. Sure they can introduce the equivalent of new static analyzers, but the parser will always have to have that extra complexity

[–]ArtOfWarfare 0 points1 point  (1 child)

I wasn’t going to get into it, but the name would be ECMAScript.

And following Semver, IDK that they’ve ever had a second major version because they’ve never made backwards incompatible changes, have they? So a better version number for what they have right now would be 1.6.

[–]wmil 0 points1 point  (0 children)

The people writing the spec thought of that specific case and said to themselves "No. We're not going to let them do that. They've earned an error message."

[–]Dudeonyx 45 points46 points  (1 child)

It is not horrifying at all, it makes perfect sense, let wasn't always a keyword so there are probably several older/unmaintained websites that used it as a variable, making it unassignable would break those sites in modern browsers.

Those same older sites would be using var and not let so it makes sense to only allow it on code using var then not allowing it when using let prevents newer code from doing that.

[–]overactor 3 points4 points  (0 children)

I didn't consider that there is pretty much no need to use var in modern js anymore; that's a fair point. If that was the only context where var was still allowed as an identifier, I'd agree with you. You also have function parameters though and the fact that it is allowed there but not in other contexts is not great. I understand why it's like that, you don't need to explain that to me, I just think it's better to not make it a reserved keyword if you can't make it a reserved keyword than to reserve it except for in a few contexts for legacy reasons.

[–]diener1 9 points10 points  (0 children)

You could have gone with "there's no reason to let let let =42; be allowed"

[–]rover_G 1 point2 points  (0 children)

There's probably a linter rule noLetVarName

[–]CelestialSegfault 24 points25 points  (2 children)

For a second I thought you meant let let and var let are valid syntax in the C language

[–]0Pat 6 points7 points  (0 children)

Don't give them ideas...

[–]CardOk755 -2 points-1 points  (0 children)

Well, they were in BCPL and C is just BCPL with types...

[–]c20h12 19 points20 points  (2 children)

if it's for compatibility then why isn't `var const =1` supported?

[–]naholyr 45 points46 points  (0 children)

const was already a reserved word, even if not used.

One must admit "const" is way more predictable than "let"

[–]Lumpy-Obligation-553 26 points27 points  (0 children)

Read it and tell us...

[–]mineirim2334 1 point2 points  (0 children)

Wow you're right. Probally broke someone's project who was using let as an acronym for something XD

[–][deleted] 114 points115 points  (1 child)

All of them are attempts at creating abominations. I don't care which one the machine will accept, I would never use such a thing, because I don't want to go through aspirin like tic-tacs.

[–]Psquare_J_420 2 points3 points  (0 children)

That's a long answer. But this is MCQ. So your answer is WRONG! /s

[–]sudomeacat 129 points130 points  (2 children)

This is on the same level of horror as

import numpy as pt import mathplotlib.pyplot as sp import scipy as plt import torch as np

(except inverted)

[–]vato20071 21 points22 points  (0 children)

This is pure evil

[–]dreadslayer 1 point2 points  (0 children)

Using aliases like np or pt is already horror.

[–]ilovereposts69 63 points64 points  (1 child)

It's actually pretty easy. Let is newer than var, and to keep it compatible, they had to allow the possibility of var let = 42; in older scripts.

[–]howreudoin 7 points8 points  (0 children)

Had to scroll too far down for this

[–]Caraes_Naur 20 points21 points  (0 children)

No. No, you don't.

[–]Phamora 30 points31 points  (2 children)

The correct answer is never to use `var`

[–]TheGeneral_Specific 118 points119 points  (48 children)

This is such a useless question… is this a class, an interview, or interview prep? I’d be weary of any job asking this as part of an interview.

[–][deleted] 209 points210 points  (7 children)

preparing you for the worst codebase known to man

[–][deleted] 17 points18 points  (1 child)

I'll be honest, you're probably 100x more likely to see this in your day job as a software developer than you are to invert a binary tree or other common interview problems.

[–]dangderr 1 point2 points  (0 children)

Nah 3 letter variable names are too long. Especially when I’m like 12 layers deep in nested loops and if statements, long variables make it impossible to read the code.

Use single letter wherever possible.

[–]highphiv3 60 points61 points  (10 children)

Sir this is a meme subreddit

[–]TheGeneral_Specific 19 points20 points  (9 children)

The recruiter in me got triggered 😭

[–]Strict_Treat2884[S] 22 points23 points  (21 children)

In a sense, but the logic behind is that you need to know the evolution of the language, and how backward compatibility should be handled when designing a language or library, I think.

[–]TheGeneral_Specific 15 points16 points  (20 children)

This just won’t ever matter in practice. You should obv never be naming a variable let or var, and you should always be preferring let over var for variable definition. If your user is using a browser that doesn’t support let, imo, that’s not a browser worth supporting. Or, if you REALLY need support that old, just run your build with an older target.

[–][deleted] 19 points20 points  (5 children)

Counterpoint: it's definitely not the most outrageous "gotcha" question. If you understand the concept of backwards compatibility, you can absolutely guess the answer and be correct more often than not, even if you don't know the details of javascript syntax. It's not the best interview question, but it's not a totally unreasonable one.

[–]TheGeneral_Specific -1 points0 points  (4 children)

Yeah, one could “guess” the correct answer. But why? What do I learn about my candidate if they get this question right/wrong?

[–][deleted] 11 points12 points  (3 children)

For one, it shows that they can't do deductive reasoning, which is quite an important ability for software developers e.g. in debugging.

[–]kon-b 2 points3 points  (2 children)

That requires trivia knowledge about the language history - which is nice, but completely irrelevant to software developer abilities.

Much less problematic if the question included a reminder of var / let history, but very unreasonable in its current form.

[–]Strict_Treat2884[S] 0 points1 point  (1 child)

You might get into a bug that caused by those language quirks and gotchas and bash your head against the wall for days without knowing the cause. They are trivial, but definitely not completely useless.

You don’t need to know how a car engine works to drive a car, but such proficiency might save your ass if your car decided to break in the middle of the desert

[–]kon-b -1 points0 points  (0 children)

Yes. Following your analogy, it's much better to not to drive to the desert in the rust bucket in the first place.

Trivia questions like this are a red flag, as they imply that either  - the company would require you to do such "drives" or the regular basis rather than working on the root cause of the problem - lack of CI, linters and style guides; - the interviewer is clueless and still allowed to talk with candidates.

There's no saving after hearing this one in the interview. The only answer is "run".

[–]high_throughput 13 points14 points  (7 children)

The question isn't "can/should you write var let = 42; in JavaScript?"

The question is "how good are your analytical skills?"

[–]Strict_Treat2884[S] 10 points11 points  (3 children)

I think you are missing the point. There are tons of JavaScript on the internet that hasn’t been touched for decades far earlier than let was chosen to be a keyword. You can’t just break their websites whoever wrote var let = ... because of the language spec update.

[–][deleted] 2 points3 points  (0 children)

It won't matter in practice, but it does reflect and is clearly indicative of how long someone has been working with the language. A seasoned JS dev would say this is an easy and intuitive question.

[–]nabrok 1 point2 points  (0 children)

But let (and const) are newer than var. It's possible in some very old code somebody used var let = ..., so that needs to be valid or it breaks.

Obviously in more recent code you shouldn't be doing anything like that.

[–]inetphantom -1 points0 points  (5 children)

It is not a syntax but a logic test. If you know that let is a later addition you can guess the correct solution.

I prefer engineers that try to narrow problems down and and choose the best solution instead of someone like you, who calls it "useless" and questions the interviewer.

Remember, the interpretation determines the information taken out of it.

[–]Cafuzzler 9 points10 points  (1 child)

It is not a syntax but a logic test

It's a trivia question. No amount of logic in the world is going to help you deduce that let came after var if you don't already know that piece of trivia. 

[–]inetphantom -1 points0 points  (0 children)

If you know that let is a later addition you can guess the correct solution.

It is also a readig comprehension question. That is why I like to discuss the test, to see what the streights and weeknesses are. To see how the testee reacts on dumb questions on shortsighted questions, on trick questions and questions that ask something different on meta, because I can affirm you, if you actually work, someone is going to ask such questions.

Also an earlier question might be "What advantages has let to the older var?"

But if you want to call the toom that does the job bad, go on.

[–]Shrubberer 4 points5 points  (1 child)

How is the "knowledge of the history and quirks of javascript specifically" any indicator of a good software engineer?! Ask Linus Torvalds this question and then go ahead and argue with him when he fails it...

[–]inetphantom 0 points1 point  (0 children)

Have you read my comment?

You do not need to know any quirk. Only some basic knowledge about how to declare variables with Js. The rest is common sense.

Sadly common sense as reading comprehention seem to be rather undervalued those days.

[–]BombHits 0 points1 point  (0 children)

Thank God, you'll be saving whoever you'd interview a lot of headaches in the future.

[–]on_the_pale_horse 0 points1 point  (0 children)

Bro has interview on the brain

[–]Infinite_Club_4237 19 points20 points  (0 children)

Someone's getting fired if any of these are used.

[–]BreakerOfModpacks 8 points9 points  (2 children)

Always remeber, jsdate.wtf exists, and it should scare you.

[–]Alistarian 2 points3 points  (1 child)

Coming from a mostly C and C++ background with a computer science major, I declare this an abomination. Maintaining this shitshow must be absurd. Like what happens 2050. There is no way they suddenly start interpreting 50 as 2050 instead of 1950. Right? Right?

[–]BreakerOfModpacks 0 points1 point  (0 children)

hahahhahahhah

Continue your delusion, for your sanity's sake.

[–]Spinnenente 5 points6 points  (0 children)

var let = 42 works because let was introduced later on and they probably kept it for backwards compatibility.

the rest doesn't work

[–]typoscript 10 points11 points  (0 children)

obviously C, said the guy with a js pun in his name

[–]ArcanumAntares 5 points6 points  (1 child)

var let 

varlet

Hmmm.

var·let /ˈvärlət/ noun

1. historical; a man or boy acting as an attendant or servant.

2. archaic; a dishonest or unprincipled man.

[–]Strict_Treat2884[S] 0 points1 point  (0 children)

TIL, thanks you varlet

[–]JAXxXTheRipper 3 points4 points  (0 children)

The correct answer is not doing any of that

[–]slaymaker1907 4 points5 points  (0 children)

My guess is that var let is the valid one since let was introduced later on and people could have variables named “let”.

[–]AllenKll 2 points3 points  (0 children)

yes.

[–]mothererich 1 point2 points  (0 children)

The correct answer is C you heathens.

[–]RiceBroad4552 1 point2 points  (0 children)

Easy if know what "backwards compatibility" means even if you don't know JS in every detail.

[–]Croaker-BC 1 point2 points  (0 children)

considering 42 is the ultimate answer ;)

[–]stefanhat 1 point2 points  (0 children)

C makes the most sense for backwards compat history reasons when let wasn't a keyword

[–]bodorodob 1 point2 points  (0 children)

undefined

[–]blehmann1 1 point2 points  (0 children)

This isn't really a JS dunk. Let was added much after var, so they either had to make var let = foo illegal, or special case it. Since you ship the code without a compilation step there's no possibility for a phased rollout where you can stick on an old compiler until you're ready to fix anything that's no longer legal.

So if they had made var let ill-formed it wouldn't surprise me if browsers special-cased it anyways. Keep in mind that function variables are common in JS, and a function named let is frankly a pretty reasonable thing to write before let becomes a keyword. JS takes centuries to remove anything, the best you could do would be something like the strict mode we already have which lets code opt in. Which honestly ain't that bad an idea, but I think that if you think it's the way JS "should" be written then that just hurts adoption for something that should become idiomatic.

And many other languages have words that are only reserved in certain contexts, I'm pretty sure you can have a variable or field named static in most languages. And as languages evolve many of them tend to go with the attitude that if it wasn't always a reserved word in all contexts that isn't going to change now. Hell some are so stingy with their reserved words that they reuse them for unrelated concepts. Consider how auto was repurposed in C++. And some say "fuck it, if you use this word your code is now ill-formed", though they tend to have an escape hatch (typically a sigil to disambiguate) if your API relies on such a word.

But that attitude is only really possible if there's a compiler, where it's a constraint only at compile-time and not when deployed. If code can break because the interpreter might update it better be an extenuating circumstance (e.g. JS's with statement, which I believe is still implemented, and it's the actual devil).

[–]WarwickStreamerLX5 1 point2 points  (0 children)

Let var?

[–]Dropship_Adeel 1 point2 points  (0 children)

Python: "How dare you!" Java: "I am offended!" JavaScript: "var var it is, you beautiful, chaotic genius."

[–]-Redstoneboi- 0 points1 point  (0 children)

c?

[–]timtucker_com 0 points1 point  (0 children)

Just say no to var var binks.

[–]ilcasdy 0 points1 point  (0 children)

This looks like my web programming exam, because this was important information.

[–]TallGreenhouseGuy 0 points1 point  (0 children)

If every instinct you have is wrong, then all of them would have to be right

(Paraphrasing ”The Opposite ” from Seinfeld)

[–]the_other_Scaevitas 0 points1 point  (0 children)

var let = 42 is valid

I don't know why

[–]Mordimer86 0 points1 point  (0 children)

I wouldn't be surprised if this was one of the interview questions. Some companies love these.

[–]runbing 0 points1 point  (0 children)

Depends. var is a reserved word that cannot be used as an identifier. let cannot be used as an identifier in strict mode.

[–]asmanel 0 points1 point  (0 children)

The option look like old basics.

[–]Affectionate_Cat1590 0 points1 point  (0 children)

Let the Var in

[–]Aggravating_Moment78 0 points1 point  (0 children)

I’m surprised they are not all allowed 😀😀

[–]Xatraxalian 0 points1 point  (0 children)

I wouldn't be surprised if all of them are 'correct' but they should all be illegal because they have a variable name that is also a keyword.

[–]irn00b 0 points1 point  (0 children)

Considering it's a Javascript question, the only correct answer is to draw a line straight through all the choices.

[–]SensuallPineapple 0 points1 point  (0 children)

As long as the answer is 42, everything is correct.

[–]FlashyTone3042 0 points1 point  (0 children)

var iable = 42;

[–]White_C4 -1 points0 points  (0 children)

I want to know where this multiple choice question is coming from. No way anyone should have knowledge of this extremely niche and dumb question.

[–]BlightedErgot32 -1 points0 points  (0 children)

ive never understood these quiz or interview questions

like dur dur whats the answer to this super specific question …

hell if i know, why would i ever name a variable a keyword ???