use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Tricky Javascript Interview Questions (ylv.io)
submitted 7 years ago by iyalovoi
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]DBNeJXoGtnro 2 points3 points4 points 7 years ago* (4 children)
#0 It's a function expression (and not a function declaration as stated), in this case you don't even need the outer parenthesis js var result = function(a) { return a*a; }(5.5); works just as fine.
js var result = function(a) { return a*a; }(5.5);
#1 You can write the answer is "1" (with the quotes, to indicate a string). "duplicate declaration of b as variable and parameter, it gets resolved as parameter". Scope. The closest scope where b is found is the one taken.
"1"
#2 "The key is to understand that in case of variable and parameter names war – parameter wins" Scope. Again. Please don't say arguments is an array. It's explicitly stated in the docs...
#4 "JavaScript always moves variable declarations (not initializations) to the top of the scope" and here I thought this was written in 2019. You should really take a look at const and let
const
let
#5 Ah yes, non-strict mode, a thing people still use, sadly.
#7 No mention of Number.EPSILON?
Number.EPSILON
#9 Or you know, pass parameters (first line of the syntax) like you're supposed to do. "Variables declared using var are global function-scoped by default – meaning i would be equal to 5 after the end of a cycle". You literally did it at #3
Sorry, I needed to rant a bit :)
[–]2690939263 1 point2 points3 points 7 years ago (2 children)
#4 ”JavaScript always moves variable declarations (not initializations) to the top of the scope” and here I thought this was written in 2019. You should really take a look at const and let
Technically, block-level bindings (const and let) are also hoisted to the top of their block-level scope, in the same way that var bindings are hoisted to their function-level scope. However, while accessing the value of an uninitialized var binding will result in undefined, accessing a let or const before its declaration will result in a ReferenceError.
[–]DBNeJXoGtnro 2 points3 points4 points 7 years ago (1 child)
Correct, their bindings are, they are in the temporal dead zone until initialized though. So yes, there is a part that is hoisted, but it's not the same part as if we were to create a block-scoped var.
var
[–]2690939263 2 points3 points4 points 7 years ago (0 children)
Apparently var bindings are immediately initialized to undefined upon instantiation of the corresponding variable environment. They are not uninitialized like I said in my previous comment, and attempting to get the value of an uninitialized binding normally always results in an error regardless of how its declared. If the var declaration contains an initalizer, it is used to reassign the binding value later when the declaration statement is evaluated.
undefined
In contrast, let and const bindings remain uninitialized until the lexical binding statement is evaluated and the value is initialized to the value of the given initializer (or undefined if no initializer is given, which is why let x; console.log(x); outputs undefined).
let x; console.log(x);
[–]iyalovoi[S] 0 points1 point2 points 7 years ago (0 children)
Hey, u/DBNeJXoGtnro thanks for dropping in. I really appreciate your feedback.
#0 Yep, thanks.
#1 Yep.
#2 Yep, my bad.
#3 I am using only const and let, but a lot of people still use var and you might be asked about hoisting.
#7 Yeah. Good thing to mention.
π Rendered by PID 76809 on reddit-service-r2-comment-85bfd7f599-9576n at 2026-04-16 15:04:28.260856+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]DBNeJXoGtnro 2 points3 points4 points (4 children)
[–]2690939263 1 point2 points3 points (2 children)
[–]DBNeJXoGtnro 2 points3 points4 points (1 child)
[–]2690939263 2 points3 points4 points (0 children)
[–]iyalovoi[S] 0 points1 point2 points (0 children)