wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JS-KT2 (Sub)

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

What will be the output of the following code snippet?

<script type="text/javascript">

a = 5 + "9";

document.write(a);

</script>

a)

Compilation Error

b)

14

c)

Runtime Error

d)

59

2.

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>

a)

al

b)

ale

c)

cal

d)

caler

3.

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>

a)

20

b)

x + y

c)

128

d)

18

4.

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

a)

1 2 3 4

b)

2 3 4 1

c)

2 4 3 1

d)

4 3 2 1

5.

What will be the output of the following code snippet?

(function(a){

return (function(){

console.log(a);

a = 6; })() })(21);

a)

6

b)

NaN

c)

21

d)

9

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

a)

[111, 44, 1, 22]

b)

[44, 1, 22, 111]

c)

[111, 44, 1, 22]

d)

[1, 22, 111, 44]

7.

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>

a)

9

b)

81

c)

Error

d)

0

8.

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

a)

4 10 18

b)

1 2 3

c)

1 4 7

d)

1 3 5

9.

What will be the output of the following code snippet?

var a = Math.max();

var b = Math.min();

print(a);

print(b);

a)

Infinity

-Infinity

b)

-Infinity Infinity

c)

Infinity

Infinity

d)

-Infinity

-Infinity

10.

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

a)

true false

b)

false true

c)

true true

d)

false false

11.

What will be the output of the following code snippet?

var a = true + true + true * 3;

print(a)

a)

3

b)

0

c)

Error

d)

5

12.

What is the output of the following code snippet?

print(NaN === NaN);

a)

true

b)

false

c)

undefined

d)

error

13.

What will be the output of the following code snippet?

print(typeof(NaN));

a)

Object

b)

Number

c)

String

d)

Boolean

14.

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

a)

true

b)

false

c)

undefined

d)

NaN

15.

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

a)

5

b)

6

c)

4

d)

3

16.

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

a)

8

b)

7

c)

0

d)

1

17.

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

a)

YES

b)

NO

c)

Syntax Error

d)

Compilation Error

18.

The 3 basic object attributes in Javascript are:

a)

Class, prototype, object's parameters

b)

Class, prototype, object's extensible flag

c)

Class, parameters, object's extensible flag

d)

Class, native object, interfaces, object's extensible flag

19.

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

a)

Boolean

b)

Undefined

c)

Object

d)

Integer

20.

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

a)

var

b)

let

c)

const

d)

constant