DEV Community

Sharad
Sharad

Posted on

10 Commonly asked Javascript Interview Questions 2018

Javascript is one of most popular programming language for the web. It is widely used for creating interactive client-side web applications and games. Javascript can be also used as server-side programming language. It is dynamic, weakly typed, prototype-based and multi-paradigm high-level programming language.

Common Javascript Interview Questions

Here we have listed 10 Common Javascript Interview Questions with their answers

1. What will be the output of variable x,y,z?

var x=10;
var y=x++;
var z=++x;
console.log(x,y,z)
Ans: It will log 12,10,12

2. What will be output of 0==-0

Answer: output of 0==-0 is true

3. What is the output of below code

function xyz () {
var abc = "hello Js";
function abc () {
return 54;
}
return abc;
}
console.log(xyz())
Answer: The above code will output hello Js.

4. How to create an object in JavaScript?

Ans: Creating an object In Javascript var object ={ name: "obj", age: 10 };

5. Explain prototypal Inheritance in JavaScript?

In JS every object has a property called a prototype, where we can add methods to it and when you create another object from these the newly created object will automatically inherit its parent’s property.

6. Explain callback in JavaScript?

A callback is a plain JavaScript function passed to some method as an argument or option. Some callbacks are just events, called to give the user a chance to react when a certain state is triggered.

7. How would you empty the below array in JavaScript?

Var emptyArray = ['this', 'array', 'is', 'full'];
Ans: Use below line of code to empty an array in JavaScript

emptyArray.length = 0;

emptyArray.splice(0, emptyArray.length);

while(emptyArray.length){
emptyArray.pop();
}

emptyArray = []

8. What will be output of below code?

var lorem = { ipsum : 1};
var output = (function(){
delete lorem.ipsum;
return lorem.ipsum;
})();

console.log(output);
Ans: The output would be undefined because the delete operator removed the property "ipsum" from the object "lorem" before the object was returned. When you reference a deleted property, the result is undefined.

9. What is output of 5 + 4 + "3"?

Since 3 is a string then the output of the above code will 93.

10. What is the real name of Javascript?

The original name of Javascript is Mocha by the Marc Addressed. He was the founder of Netscape.

Thanks for reading and good luck on your interview! Check more JavaScript Interview Questions & Answers on onlineinterviewquestions.com

Top comments (3)

Collapse
 
almokhtar profile image
almokhtar bekkour

thanks !!

Collapse
 
rocketclub2 profile image
Find Job

Try this javascript interview questions annuaire-du-net.com/javascript-int...