JavaScript Basics
JavaScript Basics - Important Points
21. | Which of the following is a primitive data type in JavaScript? |
---|
A. Number
B. Array
C. Object
D. Function
View Answer Discuss Work SpaceAnswer: option a
Explanation:
A primitive data type is a data type that is not an object and has no methods. Number is a primitive data type in JavaScript.
22. | What is the output of the following code? console.log(3 + "2"); |
---|
A. 5
B. 32
C. 6
D. 23
View Answer Discuss Work SpaceAnswer: option b
Explanation:
When a string and a number are concatenated in JavaScript, the number is converted to a string and concatenated with the other string.
23. | Which of the following is not a looping structure in JavaScript? |
---|
A. for
B. while
C. do-while
D. repeat
View Answer Discuss Work SpaceAnswer: option d
Explanation:
There is no repeat loop in JavaScript.
24. | What is the output of the following code? var x = 5; |
---|
A. 2
B. 2.5
C. 3
D. 1
View Answer Discuss Work SpaceAnswer: option d
Explanation:
The % operator in JavaScript returns the remainder of dividing two numbers. In this case, 5 divided by 2 leaves a remainder of 1.
25. | What is the output of the following code? console.log(2 + 2 + "2"); |
---|
A. 42
B. 22
C. 221
D. 4
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The expression is evaluated from left to right. First, 2 + 2 is evaluated to 4. Then, 4 is concatenated with the string "2" to produce "22".