Javascript - Mock Interview Test
1. What will be the output of the following code?
console.log(0.1 + 0.2 == 0.3);
A. true
B. false
C. undefined
D. NaN
2. What is the purpose of the `bind()` method in JavaScript?
A. To bind an object to a function
B. To bind multiple objects to a function
C. To create a shallow copy of an object
D. To execute a function immediately
3. Which of the following is a JavaScript data type?
A. Integer
B. Boolean
C. Float
D. Array
4. What is the result of the following code?
console.log(2 + '2');
A. 22
B. 4
C. 2
D. NaN
5. What does `localStorage` do in JavaScript?
A. Stores data in the browser for the current session
B. Stores data on the server
C. Stores data in the browser indefinitely
D. Stores data in a database
6. What is the difference between `null` and `undefined`?
A. `null` is an object, and `undefined` is a data type
B. `null` is used for uninitialized variables, while `undefined` represents no value
C. `null` is an empty string, while `undefined` is not a value
D. There is no difference
7. Which operator is used to check if two values are equal and of the same type?
A. `==`
B. `===`
C. `!==`
D. `=`
8. What will the following code output?
console.log([1] == 1);
A. true
B. false
C. undefined
D. TypeError
9. Which of the following is a feature of a JavaScript promise?
A. It is always synchronous
B. It can hold multiple values
C. It represents the eventual completion (or failure) of an asynchronous operation
D. It can only be used for HTTP requests
10. What does the `this` keyword refer to in JavaScript?
A. The global object
B. The current function
C. The object that invoked the function
D. The current object
11. What does `Array.prototype.map()` do?
A. It creates a new array with the results of calling a provided function on every element in the array
B. It removes elements from the array
C. It reverses the order of the array
D. It filters the elements in the array
12. Which of the following is used to define a function in JavaScript?
A. functionName()
B. functionName[]
C. functionName{}
D. functionName:()
13. What is the correct way to add a comment in JavaScript?
A. // comment
B.
C. /* comment */
D. Both A and C
14. Which method is used to select a single DOM element in JavaScript?
A. getElementById()
B. querySelector()
C. getElementsByClassName()
D. Both A and B
15. What is the result of the following expression in JavaScript?
console.log(5 + '5');
A. 55
B. 10
C. NaN
D. Error
16. How do you create a new array in JavaScript?
A. var arr = [];
B. var arr = {};
C. var arr = new Array();
D. Both A and C
17. What is the purpose of the `addEventListener()` method in JavaScript?
A. To add a callback function to an event
B. To create a new event
C. To remove an event
D. To stop an event from bubbling
18. How do you define an object in JavaScript?
A. var obj = {};
B. var obj = new Object();
C. var obj = [];
D. Both A and B
19. What is `typeof` used for in JavaScript?
A. To check the type of a variable
B. To convert a variable to a string
C. To check if a variable is defined
D. To check if a variable is an object
20. What does `console.log()` do in JavaScript?
A. Logs data to the console
B. Outputs data to the browser window
C. Alerts data to the user
D. Writes data to a file
Submit
Go Back