October 20, 2018

Srikaanth

Luxoft Most Frequently Asked Latest JavaScript Interview Questions Answers

What are the new ways to define a variable in Javascript?

There are three possible ways of defining a variable in Javascript (i) var (which is used from the beginning) (ii) const (iii) let. The last two ways are the latest ways of defining a variable and are introduced in ES-2015(ES6 version).

What is a Typed Language?

Typed Language is in which the values are associated with values and not with variables. It is of two types:

Dynamically: in this, the variable can hold multiple types; like in JS a variable can take number, chars.

Statically: in this, the variable can hold only one type, like in Java a variable declared of string can take only set of characters and nothing else.

NOTE: Typescript is a superset of JS which is of typed language.

What does a typeof operator do?

The operator typeof gives the type of a variable/data available in it. The typeof operator can be used on Reference data types also.
Luxoft Most Frequently Asked Latest JavaScript Interview Questions Answers
Luxoft Most Frequently Asked Latest JavaScript Interview Questions Answers

Name some of the ways in which Type Conversion is possible.

Type Conversion is to convert from one data type to another data type.

(i) Number to String Conversion.

toString: Other data type to String.
val = (5).toString(); converts integer to string.
val = (true).toString(); converts boolean to string.
Convert from Number/Boolean/Date to String.
Number to String: String(9) converts num to string
Boolean to String: String(true) converts bool to str
Date to String: String(new Date()) date to string
Array to String: String([2,2,2]) Array to string.

(ii) String to Number Conversion.

parseInt: String to Int only (no decimals)
val = parseInt('11'); outputs 100 as number
val = parseFloat('22.22') outputs 22.22 as float
Convert from String/Boolean to Number/Date.
String to Number: Number('9') converts str - num
(9).toFixed(4) gives 9.0000 as the output
Boolean to Number: Number(true) converts to no.
Null to Number: Number(null) converts to no. (0)
Chars to Number: Number('ss') give NaN.

What is the difference between Local Storage and Session Storage?

Local Storage will stay until it is manually cleared through settings or program.

Session Storage will leave when the browser is closed.

What is the difference between the keywords var and let?

The keyword var is from the beginning of Javascript; whereas, let is introduced in ES2015/ES6. The keyword let has a block scope; whereas, the keyword var has a functional scope.

What is the difference between the operators '=='  and '==='?

The operator '==' compares the value; whereas, the operator '===' compares both value and type.

What is the difference between null and undefined?

When used the typeof operator on null; i.e., typeof(null), the value is an object. Whereas, when used the typeof operator on undefined; i.e., typeof(undefined), the value would be undefined.

Are Javascript and JScript the same?

No, Javascript was provided by Netscape; whereas, JScript was provided by Microsoft.

Are Typescript and Javascript the same?

Typescript is not the next version of Javascript but is developed by Microsoft and can be taken as a superset to Javascript; the code written in Typescript is later compiled into Javascript. Typescript adds new features like Interfaces, Generics, etc.

Name some of the Javascript frameworks.

There are many Javascript Frameworks available today, but the most commonly used frameworks are:

(i) Angular (ii) React (iii) Vue

Explain the typeof operator.

The operator typeof is an example of Unary Operators, which is used by placing it before its operand; which can be of any type.

What are anonymous functions in Javascript?

An anonymous function allows a developer to create a function that has no name. In other words, anonymous functions can be used to store a bit of functionality in a variable and pass that piece of functionality around.

What is the difference between an Anonymous Function and a named function?

Anonymous functions exist only after they are called; whereas, Named functions to exist even if not called.

What are self Executing Functions?

These functions are executed right after its definition.  Also called as Immediately Invoked Function Expressions (IIFE's). Syntax:
(function(){
    console.log('in iffe');
})()

What is a function callback?

The callback function is a mechanism to send one function to another function as an argument; i.e., passing func as an argument to another function.

What happens when the recursion calling is applied on two functions?

The calling of recursion is possible in two functions, but the call comes to an end after some time.

Explain the term closure.

The inner functions can be called as closure when it has access to the outer function's variables.

Explain the terms synchronous and asynchronous code.

The synchronous code is something that should be finished before anything else can happen, or in other words, the synchronous code is blocking. And the Asynchronous code is something in which actions can happen and is not dependent on other actions- in other words, it is non-blocking.

Name the different types of pop up boxes in Javascript.

There are three types of pop up boxes in Javascript (i) alert() provides some information to the user with just an OK button (ii) confirm() asks a question to the user with two options Ok and cancel, and (iii) prompt() takes an input from the user.

What is the use of the ‘this’ keyword?

The keyword ‘this’ refers to the current instance of the object when used inside a function. But, when used outside a function, it refers to the window object.

Is Exception handling possible in Javascript?

With the latest version of Javascript, exception handling is possible; and this can be achieved using the following keywords try, catch and finally.

How is it possible to get the total number of arguments that are passed to a function?

The arguments.length property helps in getting the total number of arguments that are passed to a function.

What is the difference between typeof and instanceof operators in Javascript?

The typeof operator returns a string of what type the operand is. Whereas, the instanceof operator does not work with primitive data types; but works with objects and checks on what type the object is.

What is DOM?

DOM (Document Object Model) is an object-oriented representation of the HTML elements. All the elements (or nodes) are part of window.document.

Expand BOM and explain it.

BOM stands for Browser Object Model. Using BOM interaction with a browser is possible. Default object of the browser is a window.

What is the difference between window and document in Javascript?

Javascript window is a global object which holds variables, functions, history, location; the document also comes under the window and can be considered as the property of the window.

What is the difference between innerHTML and innerText?

innerHTML will process an HTML tag if found in a string, whereas innerText will not. For Example document.querySelector('p').innerHTML='one <br> two'  gives the output one and two in two lines as <br> in html is a new line. Whereas document.querySelector('p').innerText='one <br> two' gives the output of the text as it is in one line.

What is the difference between textContent and innerText?

Let us have a paragraph element and a span element in it as a child element.
<p>some text and a <span style="visibility: hidden">span tag hidden <\span>in it</p>
Now, if the following two steps would result in the following-
console.log(document.querySelector('p').textContent); gives some text and a span tag hidden in it.
console.log(document.querySelector('p').innerText); gives some text and a in it.

What is the difference between HTMLCollection and NodeList?

The functions querySelectorAll() returns NodeList in which the forEach can be used directly to traverse the elements. Whereas, the getElementsByClassName() or getElementsByTagName() returns an HTMLCollection, which does not have a forEach by default.

How can an HTMLCollection be traversed?

The HTMLCollection by default does not have forEach, it needs to be converted into an array (eleName = Array.from(eleName)) and then the traversal is possible using forEach.

What is the difference between childNode and children?

A childNode, when used returns a NodeList. Whereas, children, when used; returns an HTMLCollection.

What is the difference between firstChild and firstElementChild?

A firstChild when used returns the first node. It could be an HTML element or even a space, or a new line. Whereas, firstElementChild, when used returns the first HTML element only.

Name the two functions that are used to create an HTML element dynamically.

To generate an html element dynamically, we need to use two functions:

(i)    var ele = createElement ('elementName'), which creates an element and
(ii)   parentElement.appendChild(ele)

What is the difference between remove() and removeChild()?

The remove() function just removes the element. Whereas, the removeChild() returns the deleted element.

Subscribe to get more Posts :