JavaScript Interview Questions and Answers
Javascript Interview Questions and Answers are designed to provide a better understanding of general questions regarding JavaScript programming and its functionality, JavaScript Fundamentals , JavaScript Data Structures, Advanced JavaScript concepts etc. These questions will often link to more detailed information. Here are some of the Advanced JavaScript Interview Questions and Answers for freshers and experienced.What is memoization?
Memoizing in simple terms means that memorizing or storing in memory. Sometimes, a function can become expensive to call multiple times in a program. But there's a way you can optimize such functions and make them execute much faster is called "caching" . Memoization is a way for your function to remember (cache) the results. The concept of Memoization in Javascript is backed by two main sub-concepts: Closure and High order function. In JavaScript, closures are generated every time a function is created and it allows you access to the domain of the outer function from the inner function. A high order function accepts another function as an argument or returns a function as its output. This technique is specially useful when it comes to dynamic programming . A memoized function is usually faster because if the function is called subsequently with the previous value(s), then instead of executing the function, would be fetching the result from the cache .What is Currying in javascript
Currying is an advanced javascript technique of working with functions. It breaks down a function to takes more than one arguments into a series of functions that each take only one argument. In other words, it is a transformation of functions that translates a function from callable as f(x, y, z) into callable as f(x)(y)(z) . example
function curryThis(inArgs) {
return function doCurry(...args) {
if (args.length >= inArgs.length) {
return inArgs.apply(this, args);
} else {
return function(...args2) {
return doCurry.apply(this, args.concat(args2));
}
}
};
}
function volume(x, y, z) {
return x * y * z;
}
let curriedVolume = curryThis(volume);
console.log(curriedVolume(2, 4, 6) ); //callable normally , output: 48
console.log(curriedVolume(2)(4,6) ); //currying of 1st arg , output: 48
console.log(curriedVolume(2)(4)(6) ); //full currying , output: 48
From the above example you can understand that instead of taking all arguments at one time, takes the first one and return a new function that takes the second one and returns a new function which takes the third one, and so forth, until all arguments have been fulfilled.
What is Object Destructuring?
Object destructuring is a JavaScript expression that allow you to unpack values from a data collection (object, array, properties etc.) and maps and set them into new, distinct variables without having to iterate over the data or access its keys explicitly. example
var students = { // Object to destructure
fName: 'Jon',
lName: 'Doe',
age: 12,
yob:2000
};
// Destructuring the object into variables
var { fName, age} = students;
console.log( fName, age); //output: Jon 12
Does JavaScript support automatic type conversion?
Yes! Javascript support automatic type conversion . It's usually called type coercion. JavaScript Type Coercion means that when the operands of an operator are different data types, one of them will be converted to an equivalent value of the other operand's type .
boolean == integer
In the above code the boolean operand will be converted to an integer: false becomes 0, true becomes 1. Then the two values are compared.
example
console.log("Auto: " + 50); //return Auto: 50
Above code converts 50 (a number) to string, done by the + operator .

What is the output of the following code?
console.log(0.2 + 0.3 === 0.5);
Above code return false .
Since the floating point numbers are encoded in binary format , the addition operations on them lead to rounding errors . So, the comparison of floating points doesn't give expected results because of float point math problem .
What is Same Origin Policy?
The Same Origin Policy (SOP) is a security measure standardized among browsers. It is needed to prevent Cross-Site Request Forgery (CSRF). The "Origin" mostly refers to a "Domain". Same Origin Policy prevents different origins (domains) from interacting with each other, to prevent attacks such as CSRF (Cross Site Request Forgery) through such requests, like AJAX. In other words, the browser would not allow any site to make a request to any other site. Without Same Origin Policy , any web page would be able to access the DOM of other pages. This SOP (Same Origin Policy) exists because it is too easy to inject a link to a javascript file that is on a different domain. This is actually a security risk ; you really only want code that comes from the site you are on to execute and not just any code that is out there.How are JavaScript and ECMA Script related?
Javascript was originally created at Netscape Communications Corporation , and they wanted to standardize the language. So, they submitted the language to the ECMA for standardization. Because of trademark issues with the name Javascript, and the standard became called ECMAScript . The core functionality of Javascript are based on the ECMAScript specifications, but Javascript also has other additional features that are not in the ECMA standard . There are languages other than JavaScript (ActionScript by Adobe Flash and JScript by Microsoft) that also implement the ECMAScript Standard as their core.
What is prototypal Inheritance?
A prototype is a working object instance. An object inherits properties from another object via the prototype linkage is called Prototypal Inheritance. This means that objects inherit directly from other objects. Using this functionality, you can reuse the properties or methods from one JavaScript object to another through a reference pointer function.What is negative infinity in JavaScript?
Negative infinity is something that is lower than any other number . This means that no other number is lesser than this value. In JavaScript negative infinity is a constant value which is used to represent a value which is the lowest available .
var x = 500;
x.NEGATIVE_INFINITY;
returned "undefined"
Explain WeakSet in javascript
JavaScript WeakSets are a collection of Objects where each object can only appear once in the set, similar to Set. It contains unique objects only. If there is no reference to a stored object, they are targeted to garbage collection . WeakSet can be useful in a situation where you want to "tag" objects without actually mutating them. This means that it is useful for security and validation reasons. If you want to be able to isolate a piece of JavaScript, WeakSets allow you to tag an object to indicate it belongs to a special set of object. The only drawback is that WeakSets are not enumerable . You can't iterate over a list of entries, probably because this would likely "touch" those entries and so defeat the purpose of WeakSet concept.What are arrow functions?
Arrow functions introduced in ES6 and it aimed to address and resolve several usual pain points of traditional function expressions. They utilize the => syntax , which looks like an arrow. Arrow functions allow you to write shorter function syntax.
let sum = (x, y) => x + y;
console.log(sum(20, 45));//output is 65
Is same as,
let sum = function (x, y) {
return x + y;
};
console.log(sum(20, 45)); //output is 65
Arrow functions are more like function statements , except that they bind the this to the parent scope. The this keyword inside an arrow function , does not refer to the object calling it rather inherits its value from the parent scope.
What is the use of the "debugger" keyword?
The debugger keyword in JavaScript set the breakpoint through the code itself. It stops the execution of JavaScript, and calls the debugging function if it is available else no action is performed. Continue....... JavaScript Interview Questions (Part2)
Related Topics
- JavaScript Interview Questions (Part2)
- JavaScript Interview Questions (Part3)
- Is JavaScript a true OOP language?
- Advantages and Disadvantages of JavaScript
- Difference Between JavaScript and ECMAScript?
- What is noscript tag?
- Escaping Special Characters in JavaScript
- What is undefined x 1 in JavaScript?
- JavaScript : Logical Operators
- Difference between '=', '==' and '===' operators?
- How to reload a page using JavaScript?
- How to write html code dynamically using JavaScript?
- How to add html elements dynamically with JavaScript?
- How to load another html page from javascript?
- What Is The Disadvantages Using InnerHTML In JavaScript?
- What is Browser Object Model
- How to detect the OS on the client machine in JavaScript?
- Difference between window, document, and screen in Javascript?
- Difference between the substr() and substring() in JavaScript?
- How to replace all occurrences of a string in JavaScript?
- How to test a string as a literal and as an object ?
- What is Associative Array? How do we use it?
- What is an anonymous function in JavaScript?
- What is the use of 'bind' method in JavaScript?
- Pure functions Vs. Impure functions in javascript
- Is Javascript a Functional Programming Language?
- What's the Difference Between Class and Prototypal Inheritance?
- Javascript, Pass by Value or Pass by Reference?
- How to prevent modification of an object in Javascript?
- What is 'this' keyword in JavaScript?
- How Does Function Hoisting Work in JavaScript?
- What do mean by NULL in Javascript?
- What does the delete operator do in JavaScript?
- What is the Infinity property used for in Javascript?
- Event bubbling and Event Capturing in JavScript?
- What is "strict mode" and how is it used in JavaScript?
- What is the difference between .call() and .apply()?
- Entire content of a JavaScript source file in a function block?
- What is an immediately-invoked function expression?
- What is escape & unescape String functions in JavaScript?
- What is the instanceof operator in JavaScript?
- What Are RESTful (REpresentational State Transfer)Web Services?
- What is Unobtrusive JavaScript & Why it's Important?
- What Does JavaScript Void(0) Mean?
- What are JavaScript Cookies?
- Difference between Client side JavaScript and Server side JavaScript
- TypeError: document.getelementbyid(...) is null
- Uncaught TypeError: Cannot read property of undefined In JavaScript
- What's the difference between Null and Undefined?