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 Books
- JavaScript Projects
- JavaScript Features
- JavaScript Frameworks
- JavaScript IDE
- JavaScript Libraries
- Difference between Typescript and Javascript
JavaScript MCQ
Javascript is an _______ language?
Which of the following keywords is used to define a variable in Javascript?
Which of the following methods is used to access HTML elements using Javascript?
Upon encountering empty statements, what does the Javascript Interpreter do?
Which of the following methods can be used to display data in some form using Javascript?
Learn via our Video Courses
How can a datatype be declared to be a constant type?
What will be the output of the following code snippet?
<script type="text/javascript">
a = 5 + "9";
document.write(a);
</script>
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>
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>
When the switch statement matches the expression with the given labels, how is the comparison done?
What keyword is used to check whether a given property is valid or not?
What is the use of the <noscript> tag in Javascript?
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);
})();
What will be the output of the following code snippet?
(function(a){
return (function(){
console.log(a);
a = 6;
})()
})(21);
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);
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>
When an operator’s value is NULL, the typeof returned by the unary operator is:
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);
}
What does the Javascript “debugger” statement do?
What will be the output of the following code snippet?
var a = Math.max();
var b = Math.min();
print(a);
print(b);
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);
What will be the output of the following code snippet?
var a = true + true + true * 3;
print(a)
What is the output of the following code snippet?
print(NaN === NaN);
What will be the output of the following code snippet?
print(typeof(NaN));
What does the ‘toLocateString()’ method do in JS?
The process in which an object or data structure is translated into a format suitable for transferral over a network, or storage is called?
Which function is used to serialize an object into a JSON string in Javascript?
The 3 basic object attributes in Javascript are:
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;
}
What will be the output of the following code snippet?
a = [1, 2, 3, 4, 5];
print(a.slice(2, 4));
What will be the output of the following code snippet?
print(parseInt("123Hello"));
print(parseInt("Hello123"));
Which of the following are closures in Javascript?
Which of the following is not a Javascript framework?
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);
What keyword is used to declare an asynchronous function in Javascript?
How to stop an interval timer in Javascript?
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);
}
How are objects compared when they are checked with the strict equality operator?
What does … operator do in JS?
What will be the output of the following code snippet?
const example = ({ a, b, c }) => {
console.log(a, b, c);
};
example(0, 1, 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");
}
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);
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);
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);
What happens when we run this code?
function dog() {
print("I am a dog.");
}
dog.sound = "Bark";
How do we write a comment in javascript?
Which object in Javascript doesn’t have a prototype?
What will be the output of the following code snippet?
function test(...args) {
console.log(typeof args);
}
test(12);
What will be the output of the following code snippet?
const obj1 = {first: 20, second: 30, first: 50};
console.log(obj1);
Which of the following are not server-side Javascript objects?