JavaScript Datatypes and Variables
JavaScript Datatypes and Variables - Important Points
36. | Which of the following is a valid way to concatenate two strings in JavaScript? |
---|
A. str1 .concat(str2)
B. str1 + str2
C. str1 - str2
D. str1 * str2
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The + operator can be used to concatenate two strings in JavaScript.
37. | Which of the following is not a valid way to create a new array in JavaScript? |
---|
A. new Array(1, 2, 3)
B. [1, 2, 3]
C. Array(1, 2, 3)
D. {1, 2, 3}
View Answer Discuss Work SpaceAnswer: option d
Explanation:
The {} syntax is not a valid way to create a new array in JavaScript.
38. | What is the result of the following code snippet: typeof undefined; |
---|
A. Undefined
B. null
C. undefined
D. None of the above
View Answer Discuss Work SpaceAnswer: option c
Explanation:
The typeof operator returns a string indicating the data type of an operand, and the data type of undefined is "undefined".
39. | Which of the following is a valid way to convert a string to a number in JavaScript? |
---|
A. parseInt("42")
B. parseFloat("3.14")
C. Number("99")
D. All of the above
View Answer Discuss Work SpaceAnswer: option d
Explanation:
All three options are valid ways to convert a string to a number in JavaScript.
40. | Which of the following is not a valid way to declare a constant in JavaScript? |
---|
A. const MY_CONST = "Hello";
B. const myConst = "World";
C. var myConst = "JavaScript";
D. let myConst = "Programming";
View Answer Discuss Work SpaceAnswer: option d
Explanation:
The let keyword is used to declare a variable that can be reassigned, but const is used to declare a constant that cannot be reassigned.