JavaScript Practise - Quiz

  1. Which of the following keywords is used to define a variable in JavaScript?

A) let
B) var
C) both A and b
D) None of the above

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

A) const
B) var
C) let
D) constant

  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

  1. Which of the following is the correct output for the following JavaScript code
Int x=8;  
if(x>9)  
{  
document.write(9);  
}  
else  
{  
document.write(x);  
}  

A) 9
B) 0
C) 8
D) undefined

  1. Which of the following is the correct output for the following JavaScript code:
var x=3;  
var y=2;  
var z=0;  
If(x==y)  
document.write(x);  
elseif(x==y)  
document.write(x);  
else  
document.write(z);  

A) 3
B) 0
C) error
D) 2

Post your answers here…
Have a Happy Learning :smiley:

3 Likes

1 ) c :both A and B
2) A: const
3) A: compilation error
4) c: 8
5) b: 0

1 Like

1)C: Both A and B
2)A: const
3)D : 59
4)C : 8
5)B : 0

1 Like
  1. Option C
  2. Option A
  3. Option D
    4.Error
    5.B
  1. C
  2. const
    3.59
    4.C
    5.C
1 Like
  1. C
  2. A
  3. D
    4.Error
    5.B
1 Like

1 ) C :both A and B
2) A: const
3) A: compilation error
4) C: 8
5) B: 0

1 Like

1 c both a and b
2 a const
3 d 59
4 c 8
5 b 0

1 Like

1.Option C
2.Option A
3.Option D
4.Error
5.Option B

1 Like
  1. Option C
  2. Option A
  3. Option D
  4. Option C
  5. Option B
1 Like
  1. c
  2. A
  3. D
  4. 8
  5. 0
1 Like

The answer to the third question is 59, because 5 is a number and “9” is treated as a string, causing it to merge (concatenate values).

Answer:

  1. C
  2. A
  3. D
  4. C
  5. B
1 Like