Site icon i2tutorials

JavaScript-Quiz-5

This Quiz contains totally 10 Questions each carry 1 point for you.



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
None of the above

Correct!

Wrong!



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

Correct!

Wrong!



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


3
4
5
6

Correct!

Wrong!



4. 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
None of the above

Correct!

Wrong!



5. What happens when we run this code?

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


Syntax Error
“I am a dog” gets printed
ReferenceError
Nothing happens

Correct!

Wrong!

6. How do we write a comment in javascript?
/* */
//
#
$ $

Correct!

Wrong!

7. Which object in Javascript doesn’t have a prototype?
Base Object
All objects have a prototype
None of the objects have a prototype
None of the above

Correct!

Wrong!



8. What will be the output of the following code snippet?

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







NaN






Number






Object






Array



Correct!

Wrong!



9. What will be the output of the following code snippet?

const obj1 = {first: 20, second: 30, first: 50};
console.log(obj1);


{first: 20, second: 30}
{first: 50, second: 30}
{first: 20, second: 30, first: 50}
Syntax Error

Correct!

Wrong!

10. Which of the following are not server-side Javascript objects?
Date
FileUpload
Function
All of the above

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Ignore & go to results

JavaScript-Quiz-5

You got %%score%% of %%total%% right

%%description%%

%%description%%

Where to go ?

Quizzes

Loading...

Exit mobile version