Font size
WorksheetsJS-KT2 (Sub)
Total questions: 20
Worksheet time: 20mins
What will be the output of the following code snippet?
<script type="text/javascript">
a = 5 + "9";
document.write(a);
</script>
Compilation Error
14
Runtime Error
59
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>
al
ale
cal
caler
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>
20
x + y
128
18
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); })();
1 2 3 4
2 3 4 1
2 4 3 1
4 3 2 1
What will be the output of the following code snippet?
(function(a){
return (function(){
console.log(a);
a = 6; })() })(21);
6
NaN
21
9
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);
[111, 44, 1, 22]
[44, 1, 22, 111]
[111, 44, 1, 22]
[1, 22, 111, 44]
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>
9
81
Error
0
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); }
4 10 18
1 2 3
1 4 7
1 3 5
What will be the output of the following code snippet?
var a = Math.max();
var b = Math.min();
print(a);
print(b);
Infinity
-Infinity
-Infinity Infinity
Infinity
Infinity
-Infinity
-Infinity
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);
true false
false true
true true
false false
What will be the output of the following code snippet?
var a = true + true + true * 3;
print(a)
3
0
Error
5
What is the output of the following code snippet?
print(NaN === NaN);
true
false
undefined
error
What will be the output of the following code snippet?
print(typeof(NaN));
Object
Number
String
Boolean
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);
true
false
undefined
NaN
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);
5
6
4
3
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);
8
7
0
1
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"); }
YES
NO
Syntax Error
Compilation Error
The 3 basic object attributes in Javascript are:
Class, prototype, object's parameters
Class, prototype, object's extensible flag
Class, parameters, object's extensible flag
Class, native object, interfaces, object's extensible flag
When an operator’s value is NULL, the typeof returned by the unary operator is:
Boolean
Undefined
Object
Integer
How can a datatype be declared to be a constant type?
var
let
const
constant
