JavaScript | Technical Interview – QnA

The main purpose of a Technical interview is to test your basics and identify the depth of your knowledge. Always focus more on conceptual and fundamental topics while learning any programming language.

We have identified the most asked JavaScript interview questions here, might be really useful to revise once, before your technical interview !!

All these questions can also be asked in a “Node.js Technical Interview”.

What is JavaScript ?

Although this is a simple question, it may be hard to put things in words sometimes :

JavaScript is a Scripting / Programming Language, mostly used to add event based features in web pages.

A Scripting Language is the one that is directly implemented on run-time, not compiled earlier like C language.

What is ECMAScript ?

ECMAScript = European Computer Manufacturers Association Script.

ECMAScript is a specification that defines “how a scripting language should be created ?”.

JavaScript is an implementation of ECMAScript specification.

Evolution of ECMAScript & Features added *

[ * It is unlikely to be asked about features against the ECMAScript version, added for just the understanding ]

ECMAScript versionMajor Feature Updates
ES5The first stable ECMAScript used for JavaScript
ES6 / ES2015Arrow Functions added,
“for … of” loops added,
“let” and “const” introduced
ES7 / ES2016“await” & “async” keywords added
ES8 / ES2017“Object.values” & “Object.entries” added
ES9 / ES2018Spread Operators added
ES10 / ES2019“Array.prototype.flat” & “Array.prototype.flatMap” added, array sorting made stable
ES11 / ES2020nullish coalescing operator (??) added

Difference between “var” and “let” and “const”

A variable created with “const” cannot be assigned a new value. But, variable created by “var” and “let” can be assigned a new value.

const constA = 123;
constA = 456;
console.log("constA : ", constA);

// --- output ---
// Error: Attempting to override "constA",  which is a constant.
let letA = 123;
letA = 456;
console.log("letA : ", letA);

// --- output ---
// letA : 456
var varA = 123;
varA = 456;
console.log("varA : ", varA);

// --- output ---
// varA : 456

A variable created with “let” can be used in a block scope, where a variable created with “var” has a functional scope.

// --- var example ---
function testVar() {
  console.log("varA before if : ", varA);
  if (true) {
    let varA = "Hello !";
  }
  console.log("varA after if : ", varA);
}
testVar();

// --- output : var example ---
// varA before if : undefined
// varA after if : Hello !
// --- let example ---
function testLet() {
  if (true) {
    let letA = "Hello !";
  }
console.log("letA after if : ", letA);
}
testLet();

// --- output : let example ---
// error: Uncaught ReferenceError: letA is not defined

Difference between == and ===

A == compares the value of 2 variables, where a === compares values as well as the type of variables.

// --- let example ---
let a = 1;
let b = "1"
console.log("a == b : ", a == b);
console.log("a === b : ", a === b);
// a === b is equivalent to : (a == b && typeof a == typeof b)

// --- output ---
// a == b : true
// a === b : false

JavaScript : Synchronous OR Asynchronous ?

JavaScript is a synchronous language !
Synchronous language : Language that waits for the execution of one line before going to next line.
Asynchronous language : Language that does not wait for long tasks, like database queries to respond first (Example : Node.js)

Arrow function vs Simple function

Arrow functions were introduced in ES6 (ES2015), an arrow function does not have its own “this”. Therefore, if you use this inside arrow function, it will directly access the window object.

Ex. When you print this.demoVar inside an arrow function, it will actually print window.demoVar.
See the example, given in the snippet.

demoVar = "global";
let demoObject = {
  demoVar : "local",
  arrowFunc : () => {
    console.log("arrow function output : ", this.demoVar);
  },
  regularFunc() {
    console.log("regular function output : ", this.demoVar);
  }
  
}

demoObject.arrowFunc();
demoObject.regularFunc();

// --- output ---
// arrow function output : global
// regular function output : local

Due to this basic difference, arrow functions differ a lot from regular function.

If you want to learn in more depth about arrow functions and normal functions : You can read https://dmitripavlutin.com/differences-between-arrow-and-regular-functions/

What is TypeScript ?

TypeScript is based on JavaScript, it adds the concept of datatype in the JavaScript.
TypeScript is useful when you are working on a large codebase or in teams, because it tells you the errors on the compile time.

**********************

For the details of JavaScript Libraries, Frameworks and Job titles read our earlier blog :
JavaScript : Intro to Job Titles

Let us know about your JavaScript Interview Questions, might be helpful for a lot of us. We can include them in the next part of this blog.

Previous Post
Next Post

Comments

Node.js | Technical Interview – Questions & Answers - IT Bulls

[…] recommend you to also read our blog on JavaScript Technical Interview Questions before reading about Node.js Interview Questions. If you are confident with your JavaScript […]

Leave a Reply

Your email address will not be published. Required fields are marked *