Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
logo
Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER
/ Interview Guides / JavaScript MCQ With Answers

JavaScript MCQ With Answers

Last Updated: Nov 21, 2023
Certificate included
About the Speaker
What will you Learn?
Register Now

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. 

What will be the output of the following code snippet?

const obj1 = {first: 20, second: 30, first: 50};
console.log(obj1);
Create a free personalised study plan Create a FREE custom study plan
Get into your dream companies with expert guidance
Get into your dream companies with expert..
Real-Life Problems
Prep for Target Roles
Custom Plan Duration
Flexible Plans
2. 

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");
}
3. 

What will be the output of the following code snippet?

print(typeof(NaN));

4. 

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);
5. 

What will be the output of the following code snippet?

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

Learn via our Video Courses

6. 

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);
7. 

What will be the output of the following code snippet?

var a = Math.max();
var b = Math.min();
print(a);
print(b);
Advance your career with   Mock Assessments Refine your coding skills with Mock Assessments
Real-world coding challenges for top company interviews
Real-world coding challenges for top companies
Real-Life Problems
Detailed reports
8. 

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);
}
9. 

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);
10. 

What will be the output of the following code snippet?

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

What will be the output of the following code snippet?

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

What will be the output of the following code snippet?

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

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);
}
14. 

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);
})();
15. 

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>
16. 

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

17. 

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

18. 

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

19. 

Which object in Javascript doesn’t have a prototype?

20. 

Which of the following are closures in Javascript?

21. 

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

22. 

Which of the following is not a Javascript framework?

23. 

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

24. 

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

25. 

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

26. 

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

27. 

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

28. 

How do we write a comment in javascript?

29. 

How to stop an interval timer in Javascript?

30. 

Javascript is an _______ language?

31. 

The 3 basic object attributes in Javascript are:

32. 

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

33. 

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

34. 

What does the Javascript “debugger” statement do?

35. 

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

36. 

What does … operator do in JS?

37. 

What happens when we run this code?

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

What is the output of the following code snippet?

print(NaN === NaN);

39. 

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

40. 

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

41. 

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

42. 

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>
43. 

What will be the output of the following code snippet?

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

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);
45. 

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;
}
46. 

What will be the output of the following code snippet?

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

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);
48. 

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>
49. 

What will be the output of the following code snippet?

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

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);
Excel at your interview with Masterclasses Know More
Certificate included
What will you Learn?
Free Mock Assessment
Fill up the details for personalised experience.
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Graduation Year *
Graduation Year *
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
*Enter the expected year of graduation if you're student
Current Employer
Company Name
College you graduated from
College/University Name
Job Title
Job Title
Engineering Leadership
Software Development Engineer (Backend)
Software Development Engineer (Frontend)
Software Development Engineer (Full Stack)
Data Scientist
Android Engineer
iOS Engineer
Devops Engineer
Support Engineer
Research Engineer
Engineering Intern
QA Engineer
Co-founder
SDET
Product Manager
Product Designer
Backend Architect
Program Manager
Release Engineer
Security Leadership
Database Administrator
Data Analyst
Data Engineer
Non Coder
Other
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test