What easy questions on Javascript I can ask?

Jun 25, 2018·
Denis Trofimov
Denis Trofimov
· 2 min read
blog learning

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
Authors
Software Architect, Data Architect

Seasoned software developer, worked for start-ups, bank, industries like space and railroads.

I am a Go/Python/C++/C software engineer and working in software development since 2010. For the last 3 years I did Platform Engineering, the development of the Internal Developer Portal (IDP), and making organizations shift left on the DevOps paradigm. In the past I’ve designed and developed standalone and client-server applications, with databases like Oracle DB, PostgreSQL, and MySQL. Created applications serving CRM, web automated order processing, and simulation of the technological operation of railroad rolling stock.