What easy questions on Javascript I can ask?

In this post I speak about some basic Javascript quesions and answers, which I have made passing throught course JavaScript LaunchPad by Simple Programmer.com.

I have interviewed 3 persons in the year 2017 for developer position to the company I work for, Vzor Systems LLC.

It turned out that to prepare for interview from the interviewer side one should do some effort. If the company is not a big but a small startup, it is my job as interviewer to think of questions and written tests to check a candidate`s skills and knowledge. One time I was looking for typical questions on interview for C++ developer position.

Having an interviewer field of view in mind, I created this questions list when I have finished first **JavaScript LaunchPad **chapter “Execution Contexts and Lexical Environments”.

The Execution Context – Creation & Hoisting

Question: What this code give to the console?

b();
console.log(a);
var a = 'Hello World!';
function b() {
  console.log('Called b!');
}

Answer:

Called b!
Hello World!

Functions, Context, and Variable Environments

Question: What this code give to the console?

function b() {
  var myVar;
  console.log(myVar);
}
function a() {
  var myVar = 2;
  console.log(myVar);
  b();
}
var myVar = 1;
console.log(myVar);
a();
console.log(myVar);

Answer:

1
2
1
1

The Scope Chain

Question: What this code give to the console?

function a() {
  function b() {
    console.log(myVar);
  }
  b();
}
var myVar = 1;
a();
b();

Answer:

1
Uncaught ReferenceError: b is not defined

What About Asynchronous Callbacks

Question: What this code give to the console?

// long running function
function waitThreeSeconds() {
  var ms = 3000 + new Date().getTime();
  while (new Date() < ms){}
  console.log('finished function');
}
function clickHandler() {
  console.log('click event!');
}
// listen for the click event
document.addEventListener('click', clickHandler);
waitThreeSeconds();
console.log('finished execution');

Answer:

finished function
finished execution
click event!
Denis Trofimov
Denis Trofimov
Lead Platform Engineer

Lead Cloud Platform Developer. I enjoy creating Kubernetes Operators and such :)