JavaScript Datatypes and Variables
JavaScript Datatypes and Variables - Important Points
11. | Which of the following is a valid way to declare a variable with global scope in JavaScript? |
---|
A. var myVar;
B. let myVar;
C. const myVar;
D. All of the above
View Answer Discuss Work SpaceAnswer: option a
Explanation:
Using the var keyword to declare a variable without specifying a block scope makes it a global variable.
12. | Which of the following is a valid way to convert a string to a number in JavaScript? |
---|
A. parseInt("10");
B. 10.toInt();
C. 10.toNumber();
D. Number("10");
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The parseInt() function can be used to convert a string to a number in JavaScript.
13. | What is the data type of a variable that stores a null value in JavaScript? |
---|
A. Object
B. Null
C. Undefined
D. Number
View Answer Discuss Work SpaceAnswer: option a
Explanation:
In JavaScript, null is considered to be an object data type.
14. | Which of the following is not a valid way to declare a variable in JavaScript? |
---|
A. var 1myVar = 1;
B. let myVar1 = 1;
C. const MYVAR = 1;
D. let $myVar = 1;
View Answer Discuss Work SpaceAnswer: option a
Explanation:
Variable names in JavaScript cannot start with a number.
15. | What is the data type of a variable that stores a function in JavaScript? |
---|
A. Function
B. Object
C. Method
D. Action
View Answer Discuss Work SpaceAnswer: option b
Explanation:
In JavaScript, functions are considered to be objects.