Top 20 JavaScript interview Questions & Answers - part 2 | textpound



Top 20 JavaScript interview Questions & Answers - part 2


Javascript interview Questions
JavaScript Interview Questions and Answers



14. What is prototype Inheritance in JavaScript?

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.

15. What is a prompt box in JavaScript?

A prompt box is a box which allows the user to enter input by providing a text box. Label and box will be provided to enter the text or number.

window.prompt("message","defaultText") or

this.prompt("message","defaultvalue")



16. How we can display line breaks inside a popup box?

we can display line breaks inside a popup box use a back-slash followed by the character n.


Example:
alert("How old are you\n21?");


17. What is the difference between DOM and BOM?


DOM stands for Object Document Model and BOM stands for Browser Object Model.

18. What is === operator in JavaScript?

=== is called as strict equality operator which returns true when the two operands are having the same value without any type conversion.

19. What is Callback Function in JavaScript?


It is a function that is to be executed after another function has finished executing, hence the name ‘call back‘. 

20. What is TypeOf Operator in JavaScript?

The typeof operator is used to get the data type of its operand.

Example:
let a=typeof 7
console.log(a) // "number"


21. Which built-in method sorts the elements of an array in JavaScript?

Sort method in javasorts sorts the elements of an array.
Example:

let Name = ["ravi", "sham", "jhon", "Mango"];
fruits.sort();


22. How can the style/class of an element be changed using JavaScript?


It can be done in the following way:

document.querySelector("#myText").style.fontSize = "20px";
or
document.querySelector("#myText").className = "classname"; 


23.Explain the difference between "==" and "==="?


"==" checks only for equality in value whereas "===" is a stricter equality test and also check the type of the two variables.If the type is different then it return false.

Example:
console.log("4"==4) // true
console.log("4"===4)//false 

24. What is the difference between null & undefined in JavaScript?


Undefined means a variable has been declared but has not yet been assigned a value.The variable get value of Undefined by default when it has not been assigned a value On the other hand, null is an assignment value. 

25. How we can defined an array in JavaScript?

We can defined an array using array literal or Array constructor syntax.

Array literal syntax:

let arrayName = ["one", "two", "three"];

Array constructor syntax:

let arrayName = new Array(3);


Post a Comment

0 Comments