1: What does JavaScript primarily add to a web Page?
A) Style
B) Interactivity
C) Structure
D) Images
2: What is the correct way to declare a variable In JavaScript?
A) Let myVar = 10;
B) Var myVar = 10;
C) Const myVar = 10;
D) All of the above
Which of the following is a falsy value
JavaScript?
A) 0
B) “false”
C) Undefined
D) All of the above
What is the purpose of the Document.getElementById() method in JavaScript?
A) To get the value of an input element
B) To change the page’s title
C) To get an element by its ID
D) To add a new HTML element
Which operator is used for equality without Type coercion in JavaScript?
==
B) ==
C) =
E) !==
What is the correct way to comment a single Line in JavaScript?
A) // This is a comment
B) /* This is a comment */
C) <!—This is a comment →
D) % This is a comment %
Which function is used to add a new element At the end of an array in JavaScript?
A) Push()
B) Pop()
C) Shift()
D) Unshift()
What is the purpose of the setTimeout() Function in JavaScript?
A) To set the text of an element
B) To execute a function after a specified delay
C) To change the color of an element
D) To create a new object
Which of the following is not a valid JavaScript data type?
A) String
B) Object
C) Function
D) Character
What does the addEventListener() method Do in JavaScript?
A) Adds a new element to the page
B) Adds a click event to an element
C) Changes the page’s background color
D) Removes an element from the page
How do you declare a function in JavaScript?
Function myFunction() {}
A) Var myFunction = function() {}
B) Let myFunction = () => {}
C) All of the above
What is the purpose of the localStorage
Object in JavaScript?
A) To store session data on the server
B) To store data in the client’s browser
C) To make AJAX requests
D) To create a new JavaScript file
What is the result of the expression 5 + “5” In JavaScript?
A) 55
B) 10
C) “10”
D) 15
Which keyword is used to prevent variable
Hoisting in JavaScript?
A) Let
B) Var
C) Const
D) Hoist
What is the purpose of the return Statement in a JavaScript function?
A) To stop the function’s execution
B) To return a value from the function
C) To print a message to the console
D) To declare a new variable
Which method is used to remove the last Element from an array in JavaScript?
A) Slice()
B) Remove()
C) Pop()
D) Delete()
How can you convert a string to an integer
In JavaScript)?
A) parseInt()
B) toInt()
C) convertToInt()
D) strToNum()
What is the purpose of the typeof operator In JavaScript?
A) To check if a variable is undefined
B) To check the type of a value or variable
C) To convert a value to a different type
D) To check if a variable is null
Which loop is used to iterate over the Properties of an object in JavaScript?
A) For loop
B) while loop
C) for…in loop
E) Do…while loop
What is the purpose of the JSON.parse()
Function in JavaScript?
A) To convert a string to a JSON object
B) To stringify an object
C) To change the value of a variable
D) To add a new element to an array
What is the correct way to add a comment That spans multiple lines in JavaScript?
A) /* This is a comment */
B) // This is a comment
C) <!—This is a comment →
D) # This is a comment #
What is the purpose of the Array.isArray()
Method in JavaScript?
A) To check if a variable is an array
B) To add an element to an array
C) To remove the first element from an array
D) To convert an object to an array
Which JavaScript operator is used to Combine two or more strings?
A) +
B) &
C) /
D) –
What does the Math.random() function
Return in JavaScript?
A) A random integer
B) A random boolean value
C) A random floating-point number between 0 (inclusive) and 1 (exclusive)
D) A random string
What is the purpose of the try…catch
Statement in JavaScript?
A) To define a new function
B) To declare a variable
C) To handle exceptions and errors
D) To create a loop
What will happen, if the following JavaScript code is executed?
Var count =0;
While (count <10)
{ Console.log(count);
Count++;
A)An error is displayed
B)An exception is thrown
C)The values of count variable are logged or stored in a particular location or storage
D)The value of count from 0 to 9 is displayed in the console
What will be the output of the following JavaScript code snippet?
<p id=”demo”></p> var txt1 = “Sanfoundry_”; var txt2 = “Javascriptmcq”;
document.getElementById(“demo”).innerHTML = txt1 + txt2;
a) error
b) Sanfoundry_ Javascriptmcq
c) undefined
d) Sanfoundry_Javascriptmcq
What will be the output of the following JavaScript code?
<p id=”demo”></p> <script> var js = 10; js *= 5;
document.getElementById(“demo”).innerHTML = js; </script>
a) 10
b) 50
c) 5
d) Error
Arrays in JavaScript are defined by which of the following statements?
a) It is an ordered list of values
b) It is an ordered list of objects
c) It is an ordered list of string
d) It is an ordered list of functions
What will be the output of the following JavaScript code?
// JavaScript Comparison Operators function
compare() { int num=2; char b=2; if(a==b) return true; else return false }
a) false
b) true
c) compilation error
d) runtime error
Will the following JavaScript code work?
Var js = (function(x) {return x*x;}(10));
a) Exception will be thrown
b) Memory leak
c) Error
d) Yes, perfectly
Where is Client-side JavaScript code is embedded within HTML documents?
a) A URL that uses the special javascript:code
b) A URL that uses the special javascript:protocol
c) A URL that uses the special javascript:encoding
d) A URL that uses the special javascript:stack
What will be the output of the following JavaScript program?
Function sanfoundry(javascript) { return (javascript ? “yes” : “no”); } bool ans=true;
console.log(sanfoundry(ans));
a) Compilation error
b) Runtime error
c) Yes
d) No
What will be the output of the following JavaScript code?
// Javascript code snippet to compare the height
function height() { var height = 123.56; var type = (height≥190) ? “tall” : “short”; return type; }
a) short
b) 123.56
c) tall
d) 190
What will be the output of the following JavaScript function?
<p id=”demo”></p> <script> function javascript() { // javacript abs() method
document.getElementById(“demo”).innerHTML = Math.abs(-7.25); } </script>
a) -7.25
b) 7.25
c) -7
d) 7
What will be the output of the following JavaScript code?
Var a=5 , b=1 var obj = { a : 10 } // with keyword in JavaScript with(obj) { alert(b) }
a) 1
b) 10
c) 5
d) Error
What will be the output of the following JavaScript code?
Function printArray(a) { var len = a.length, i = 0;
if (len == 0) console.log(“Empty Array”);
else { // do-while loop in javascript do { console.log(a[i]); } while (++i < len); } }
a) Prints “Empty Array”
b) Prints 0 to the length of the array
c) Prints the numbers in the array in order
d) Prints the numbers in the array in the reverse order
Consider the following JavaScript statement containing regular expressions and check if the pattern
matches.
Var text = “testing: 1, 2, 3”; var pattern = /d+/g;
a) text.check(pattern)
b) pattern.test(text)
c) text==pattern
d) text.equals(pattern)
What will be the output of the following JavaScript code?
Function compare() { int sanfoundry=1; char javascript=1; if(sanfoundry.tostring()===javascript)
return true; else return false; }
a) runtime error
b) logical error
c) true
d) false
Which of the following is not a framework?
a) JavaScript .NET
b) JavaScript
c) Cocoa JS
d) jQuery
Which of the following methods/operation does javascript use instead of == and !=?
a) JavaScript uses equalto()
b) JavaScript uses equals() and notequals() instead
c) JavaScript uses bitwise checking
d) JavaScript uses === and !== instead
What will be the output of the following JavaScript code?
Int a=0; for(a;a<5;a++); console.log(a);
a) 4
b) 5
c) 0
d) error
What will be the output of the following JavaScript code?
Var quiz=[1,2,3]; var js=[6,7,8]; var result=quiz.concat(js); document.writeln(result);
a) 1, 2, 3, 6, 7, 8
b) 123
c) 1, 2, 3
d) Error
https://www.w3schools.com/quiztest/quiztest.asp?qtest=JS
By:NADA AYMAN♡.