Test Your JavaScript Knowledge - JavaScript/ES6 Interview Questions and Answers
Some minor comments:
Q2: "Local scope can be local to a function or a block." Or module - another local scope
Q2: "Variables defined using var have function scope."/"Variables and constants defined using let and const have block scope." Unless used in the global scope, at which point they're global
Q2: "In case of a block scoped variable, its value is inaccessible before its first assignment." More accurately, its before the location of the declaration. You can declare a variable with
letwithout defining it and still be able to access it prior to its first assignment.let x;
console.log(x); // Ok, = undefined
x = 1; // first assignmentQ3: "JavaScript functions have prototypes." Not all functions. Arrow functions and methods do not.
() => {} // no prototype
{ foo(){} } // foo: no prototype
class { foo(){} } // foo: no prototypeQ5 (and Q4): No use of super.deposit()?
Q6: "In JavaScript,
thisis a function scoped variable." It also exists in global.Q6: "Under normal circumstances,
thisrefers to the object owning the function." Specifically, the function call, not the function itself.this, under those normal circumstances, is determined dynamically at call time and applies to the call itself rather than the function object.Q6: "In global functions,
thisequals the global scope." Only if its being called from the global object, otherwise itsundefined(given that it was mentioned earlier, "this test is in strict mode").Q8: "When using the global symbol registry, we get the exact same symbol belonging to the string
'a', whenever we callSymbol.for( 'a' )." This feels a little out of place without first mentioning how symbols are inherently unique.Q9: "A correct check [to see if a value is an Array] is the usage of the
instanceofoperator:" This is a way to check, but its less correct than the best solution ofArray.isArray... though still more correct than comparing theconstructor. Actually thetypeofchecks below might be better since it works across multiple globals. WithoutisArray, its often suggested instead to useObject.prototype.toStringand compare to"[object Array]"since it would work in most cases, though even this approach can be interfered with usingtoStringTag. At any rate, I think the usage of "correct" should fall toisArrayand notinstanceof.
Using ES6 for interview questions?
I'm a senior JS guy and I only expect my candidates to know ES5 when I interview. Same expectations among my colleagues.
More on reddit.com