Being great developer has nothing to do with passing interview, because most interviews are about weird questions, like what are your weaknesses and question about the legacy feature of a language which nobody hasn’t used in 10 years. Nevertheless, we have to play the game by the rules. #0 Tricky Function Call What is the output in the console? Answer The answer is . The trick is, if you put parentheses with arguments immediately after function declaration, that will be considered a function call. 30.25 #1 Fat Arrow + Declaration Overlap What is the output in the console? Answer The answer is . The trick is that due to duplicate declaration of b as variable and parameter, it gets resolved as parameter. Since we call our function only with parameter – equals . Pay attention that type of returned value is string. 1 1 1 + [] '1' #2 Variable and Function Names Overlap What is the output in the console? Answer Output will be . The key is to understand that in case of variable and parameter names war – parameter wins. There are a few other tricks here. is always an array and in this case it is . is a way to group the rest of the function parameters into named array, in this case all the parameters are resulting into . [10], 10, [10], 10 arguments [10] ...f [10] #3 Variable Scope What is the output in the console? Answer There are two tricks here. First — executing code using function scope — pattern. Second – exploiting global/local scope overlap. Both and defined in global scope. Function redefines in local scope, so global is not changed, when gets reassigned to . Finally, . (function(){}()) foo bar foo foo bar 1 1 + 10 = 11 #4 Global + Local What is the output in the console? Answer This will print out and rather than and since JavaScript always moves variable declarations (not initializations) to the top of the scope, making the code equivalent to: undefined 10 5 10 #5 Chained Assignment What is the output in the console? Answer This will print out and rather than and since is equivalent to . Making global variable. What is usage of chained notation is not recommended by many styles to avoid accidental global variable declarations. undefined number number number var a = b = 3 b = 3; var a = b; b #6 Auto Semicolon What is the output in the console? Answer This will print out and . Javascript has and one of them is inserting semicolon after return statement, making second function equal to , thus returning . object undefined automatic semicolon insertion return; undefined #7 Javascript Number What is the output in the console? Answer Most likely it will output , , and . Number in JS are represented as values. Thus there are rounding errors, as well as there is , after which equals to . 0.30000000000000004 false true double-precision 64-bit binary format IEEE 754 Number.MAX_SAFE_INTEGER Number.MAX_SAFE_INTEGER === Number.MAX_SAFE_INTEGER + 1 true #8 Object Keys What is the output in the console? Answer This will print out , not . When setting an object property, JavaScript will implicitly the parameter value. In this case, since and are both objects, they will be converted to . As a result, and are both equivalent to and can be used interchangeably. Thus, setting or referencing is precisely the same as setting or referencing . 333 111 stringify b c both "[object Object]" a[b] a[c] a["[object Object]"] a[c] a[b] #9 setTimeout Loops What is the output in the console? Answer This will print out and . 5, 5, 5, 5, 5 0, 1, 2, 3, 4 function will be called after whole cycle is executed because of JavaScript event queue. Variables declared using are global by default – meaning would be equal to after the end of a cycle. Since all setTimeout functions are called after the cycle, the all would print . setTimeout var i 5 5 Output of second loop even more bizarre. In , the specified behaviour is that in gets a new binding for every iteration of the loop. Essentially each closure inside a loop gets a different instance of ECMA 6 specification for(let i;;){} i i #10 Chained Relationals What is the output in the console? Answer This will print out and . There are two tricks here. In Javascript relational operators evaluated from left to right, false equals , and true equals for number comparisons. First expression after first step is => => , and second is => => . true false 0 1 true < 2 1 < 2 true true > 1 1 > 1 false TL; DR; Javascript has many interview traps, so unless you prepare for them or have memorized ECMA specifications you are likely to fail at an interview at some point. If this post was helpful, please click the clap 👏button below a few times to show your support! ⬇⬇ Social Connect with me on . LinkedIn Follow me on . twitter Originally published at ylv.io on February 10, 2019.