Skip to content

JavaScript Interview Questions

Reading Time: 3 minutes

If you’re planning to attend the Front End developer interview, then you must know about JavaScript. Here are the most important and probably asked JavaScript interview questions.

1. Explain JavaScript?

JavaScript is a scripting language used in both client side and server side scripting. It is also an object oriented programming language that allows you to build static HTML pages.

2. List the JavaScript types?

  • Boolean
  • Function
  • Null
  • Objects
  • String
  • Number
  • Undefined

3. How to create an object in JavaScript?

Object in Javascript can be created in three ways

  • By using Object literal
  • By creating instance of object
  • By using object constructor
var empl={

firstname:”ziva”

Age:25

Id:255

};

4. What is negative infinity?

A number derived by dividing negative numbers by zero in JavaScript gives negative infinity.

5. Write a code to create an array in JavaScript?

Array can be created in three ways in JavaScript

  • By  using array literal
  • By using an Array constructor
  • By creating instance of Array
var emp=["Dhoni","Virat",”Ziva"];

6. What is DOM?

Document Object Model-DOM. DOM represent the html document and it is used to access and change the content of the HTML.

7. What will be the output of the given code?

var output = (function(y){

delete y;

return y;

})(0);

console.log(outputvalue);
Output

0
Explanation

Here delete operator deletes the properties from an object. But X here is a local variable. so delete property does not affect local variable.

8. List all types of pop up boxes available in JavaScript?

  • Confirm
  • Prompt
  • Alert

9. Explain break and continue statement?

Break statement exits from the current loop and continue statement continues with the next statement of the loop.

See also  SharePoint Interview Questions

10. Write the output of following code?

var y= 1;

var output = (function(){

delete y;

return y;

})();

console.log(output value);
Output

1

11. What is” == “operator?

When two operators are having the same value without any type conversion “==” operators return True. It is also called as a strict equality operator.

12. List the looping structures in JavaScript?

  • While
  • do-while loops
  • For

13. List all the keywords used to handle exceptions?

Try

Catch and

finally is used to handle exceptions

Try{
Code
}
Catch(expect){
Code to throw an exception
}
Finally{
Code runs it finishes successfully or after catch
}

14. What are the screen objects in JavaScript?

It is used to read the information from the client side

  • AvailWidth
  • AvailHeight
  • ColorDepth
  • Height
  • Width

15. write syntax to create function in JavaScript?

To create Function in JavaScript

function function_name(){

//function body  content

}

16. What are two data types in JavaScript?

  • Primitive Data Types
  • Non-primitive Data Types

javascript interview questions

17. Write a code to get the total number of arguments passed to a function?

By using arguments.length property we can get the total number of arguments passed to a function.

function func(y){

console.log(typeof y, arguments.length);

}

18. What is a closure?

It is created whenever a variable is accessed which is defined outside the current scope is accessed from within the some inner scope.

19. List some advantages of using JavaScript?

  • Speed
  • Server Load
  • Versatility
  • simple Implementation

20. Write a Hello world example of JavaScript?

<script type="text/javascript">

document.write("Hello World");

</script>

21. How to use external JavaScript files?

External JavaScript can be used to embed all the JavaScript files into a single file. JavaScript.

<script type="text/javascript" src="externaljavascript.js"></script>

22. Is JavaScript is a case sensitive language?

Yes, JavaScript is a case sensitive language.

See also  Active Directory Interview Questions

23. What is a use of history object?

History object is used to switch to history page such as forward and back from the current page or another page in a browser. The three types of history objects are

  • history.forward()
  • history.back()
  • history.go(number): number may be “+”for forward, “-“ for backward.

24. List the valid scopes of the variable?

  • Global Variables- It is visible everywhere in the  JavaScript code.
  • Local Variables- It is visible only within the function.

25. How to get the reference of a caller function inside a function?

The arguments have a callee property, which makes you the reference to the function you’re inside of .

function func() {

return arguments.callee;

}

Leave a Reply