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

Code:
<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
πŸ’¬ Discuss
βœ… Correct Answer: (A) al

Q. When the switch statement matches the expression with the given labels, how is the comparison done?

  • (A) Both the datatype and the result of the expression are compared.
  • (B) Only the value of the expression is compared.
  • (C) Only the datatype of the expression is compared.
  • (D) None of the above.
πŸ’¬ Discuss
βœ… Correct Answer: (A) Both the datatype and the result of the expression are compared.

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

Code:
<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) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) 20

Q. What is the use of the <noscript> tag in Javascript?

  • (A) The contents are displayed by non-JS-based browsers.
  • (B) Clears all the cookies and cache.
  • (C) Both A and B.
  • (D) None of the above.
πŸ’¬ Discuss
βœ… Correct Answer: (A) The contents are displayed by non-JS-based browsers.
Explanation:

The <noscript> tag is used in HTML to provide alternative content for users who either have JavaScript disabled in their browser or are using browsers that do not support JavaScript. It does not clear cookies or cache.

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

Code:
(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
πŸ’¬ Discuss
βœ… Correct Answer: (C) 2 4 3 1

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

Code:
(function(a){
 return (function(){
   console.log(a);
   a = 6;
 })()
})(21);
  • (A) 6
  • (B) NaN
  • (C) 21
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (C) 21

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

Code:
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]
πŸ’¬ Discuss
βœ… Correct Answer: (A) [111, 44, 1, 22]

Q. What will be the output for the following code snippet?

Code:
<p id="example"></p>  
<script>  
function Func()  
{  
document.getElementById("example").innerHTML=Math.sqrt(81);  
}  
</script>
  • (A) 9
  • (B) 81
  • (C) Error
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (A) 9

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

  • (A) Boolean
  • (B) Undefined
  • (C) Object
  • (D) Integer
πŸ’¬ Discuss
βœ… Correct Answer: (C) Object

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

Code:
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) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) 4 10 18