Scaler
Practice
Resources
Contests
Online IDE
New
Free Mock
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders

Welcome to Interviewbit, help us create the best experience for you!

Currently, You are a:

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your career...

Current Company *
Enter company name
Experience *

You're all set!

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

JavaScript MCQ With Answers

Javascript is one of the most popular programming languages in the world currently, and it is basically the language of the web. It is a lightweight, cross-platform, and interpreted programming language, primarily used for web development and backend development. Javascript is a language that is used widely on both the client and server sides of development. Javascript offers a vast standard library that has a wide variety of functions and methods available to help in the process of development, making the entire process easier and hassle-free.

Javascript can be added to our HTML code in mostly 2 ways:

  • Internal Javascript: Javascript in this case is directly added to the HTML code by adding the JS code inside the <script> tag, which can be placed either inside the <head> or the <body> tags based on the requirement of the user.
  • External Javascript: In this case, the Javascript code is written inside an external file with the extension file_name.js, and then the file is linked to the HTML file inside the <head> tag.

Features of Javascript

  • Javascript is a lightweight, cross-platform, and interpreted language.
  • It was developed with the main intention of DOM manipulation, bringing forth the era of dynamic websites.
  • Javascript functions are objects and can be passed in other functions as parameters.
  • Can handle date and time manipulation.
  • Can perform Form Validation.
  • A compiler is not needed.

Useful Resources

 

JavaScript MCQ

1. 

Javascript is an _______ language?

2. 

Which of the following keywords is used to define a variable in Javascript?

3. 

Which of the following methods is used to access HTML elements using Javascript?

4. 

Upon encountering empty statements, what does the Javascript Interpreter do?

5. 

Which of the following methods can be used to display data in some form using Javascript?

6. 

How can a datatype be declared to be a constant type?

7. 

What will be the output of the following code snippet?

<script type="text/javascript">
a = 5 + "9";
document.write(a);
</script>
8. 

What will be the output of the following code snippet?

<script type="text/javascript" language="javascript">
  
var a = "Scaler";
var result = a.substring(2, 4);
document.write(result);
  
</script>
9. 

What will be the output of the following code snippet?

<script type="text/javascript" language="javascript">
 
var x=12;
var y=8;
var res=eval("x+y");
document.write(res);
 
</script>
10. 

When the switch statement matches the expression with the given labels, how is the comparison done?

11. 

What keyword is used to check whether a given property is valid or not?

12. 

What is the use of the <noscript> tag in Javascript?

13. 

What will be the output of the following code snippet?

(function(){
 setTimeout(()=> console.log(1),2000);
 console.log(2);
 setTimeout(()=> console.log(3),0);
 console.log(4);
})();
14. 

What will be the output of the following code snippet?

(function(a){
 return (function(){
   console.log(a);
   a = 6;
 })()
})(21);
15. 

What will be the output of the following code snippet?

function solve(arr, rotations){
 if(rotations == 0) return arr;
 for(let i = 0; i < rotations; i++){
   let element = arr.pop();
   arr.unshift(element);
 }
 return arr;
}
// solve([44, 1, 22, 111], 5);
16. 

What will be the output for the following code snippet?

<p id="example"></p>  
<script>  
function Func()  
{  
document.getElementById("example").innerHTML=Math.sqrt(81);  
}  
</script>
17. 

When an operator’s value is NULL, the typeof returned by the unary operator is:

18. 

What will be the output of the following code snippet?

var a = 1;  
var b = 0;  
while (a <= 3)  
{  
   a++;  
   b += a * 2;  
   print(b);
}
19. 

What does the Javascript “debugger” statement do?

20. 

What will be the output of the following code snippet?

var a = Math.max();
var b = Math.min();
print(a);
print(b);
21. 

What will be the output of the following code snippet?

var a = Math.max() < Math.min();
var b = Math.max() > Math.min();
print(a);
print(b);
22. 

What will be the output of the following code snippet?

var a = true + true + true * 3;
print(a)
23. 

What is the output of the following code snippet?

print(NaN === NaN);

24. 

What will be the output of the following code snippet?

print(typeof(NaN));

25. 

What does the ‘toLocateString()’ method do in JS?

26. 

The process in which an object or data structure is translated into a format suitable for transferral over a network, or storage is called?

27. 

Which function is used to serialize an object into a JSON string in Javascript?

28. 

The 3 basic object attributes in Javascript are:

29. 

What will be the output of the following code snippet?

let sum = 0; 
const a = [1, 2, 3];
a.forEach(getSum);
print(sum);
function getSum(ele) {
   sum += ele;
}
30. 

What will be the output of the following code snippet?

a = [1, 2, 3, 4, 5];
print(a.slice(2, 4));
31. 

What will be the output of the following code snippet?

print(parseInt("123Hello"));
print(parseInt("Hello123"));
32. 

Which of the following are closures in Javascript?

33. 

Which of the following is not a Javascript framework?

34. 

What will be the output of the following code snippet?

var a = "hello";
var sum = 0;
for(var i = 0; i < a.length; i++) {
   sum += (a[i] - 'a');
}
print(sum);
35. 

What keyword is used to declare an asynchronous function in Javascript?

36. 

How to stop an interval timer in Javascript?

37. 

What will be the output of the following code snippet?

const set = new Set();
set.add(5);
set.add('Hello');
set.add({ name: 'Scaler' });
for (let item of set) {
 console.log(item + 6);
}
38. 

How are objects compared when they are checked with the strict equality operator?

39. 

What does … operator do in JS?

40. 

What will be the output of the following code snippet?

const example = ({ a, b, c }) => {
 console.log(a, b, c);
};
example(0, 1, 2);
41. 

What will be the output of the following code snippet?

let a = [1, 2, 3, 4, 5, 6];
var left = 0, right = 5;
var found = false;
var target = 5;
while(left <= right) {
   var mid = Math.floor((left + right) / 2);
   if(a[mid] == target) {
       found = true;
       break;
   }
   else if(a[mid] < target) {
       left = mid + 1;
   }
   else {
       right = mid - 1;
   }
}
if(found) {
   print("YES");
}
else {
   print("NO");
}
42. 

What will be the output of the following code snippet?

let s = "00000001111111";
let l = 0, r = s.length - 1, ans = -1;
while(l <= r) {
   var mid = Math.floor((l + r) / 2);
   if(s[mid] == '1') {
       ans = mid;
       r = mid - 1;
   }
   else {
       l = mid + 1;
   }
}
print(ans);
43. 

What will be the output of the following code snippet?

let n = 24;
let l = 0, r = 100, ans = n;
while(l <= r) {
   let mid = Math.floor((l + r) / 2);
   if(mid * mid <= n) {
       ans = mid;
       l = mid + 1;
   }
   else {
       r = mid - 1;
   }
}
print(ans);
44. 

What will be the output of the following code snippet?

const obj1 = {Name: "Hello", Age: 16};
const obj2 = {Name: "Hello", Age: 16};
print(obj1 === obj2);
45. 

What happens when we run this code?

function dog() {
   print("I am a dog.");
}
dog.sound = "Bark";
46. 

How do we write a comment in javascript?

47. 

Which object in Javascript doesn’t have a prototype?

48. 

What will be the output of the following code snippet?

function test(...args) {
 console.log(typeof args);
}
test(12);
49. 

What will be the output of the following code snippet?

const obj1 = {first: 20, second: 30, first: 50};
console.log(obj1);
50. 

Which of the following are not server-side Javascript objects?

Get Placed at Top Product Companies with Scaler Know More 
Get Placed at Top Product Companies with Scaler Know More 
Get Placed at Top Product Companies with Scaler
Sat transparent 640a34d454880bf68e3bfdf33f2389f2214043f59ad18b4c7f7b114e834fb257.svg

Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Personalised feedback report with solutions
Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Real life Interview Questions
Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Identify exact topics to improve

Your feedback is important to help us improve.
Free Mock Assessment
Help us know you better for the best experience
Current Employer *
Enter company name
College you graduated from *
Enter university name
Phone Number *
OTP will be sent to this number for verification
+1
+1
Change Number
Edit
Resend OTP
By Continuing I agree to be contacted by Scaler in the future.
Already have an account? Log in