Web Designing MCQs

MCQ On JavaScript Types, Values And Variables Part-2

Pinterest LinkedIn Tumblr
This set of MCQ on JavaScript types, value, and variables includes MCQ on JavaScript type conversions, explicit conversion, and object to primitive conversions used in JavaScript. It also includes the difference between primitive values and mutable object reference and equality in JavaScript.

1. Any value other than ………………… has a tostring( ) method and the result of this method is usually the same as that returned by the string( ) function.
i) number     ii) null    iii) boolean   iv) undefined
A) i and ii only
B) ii and iii only
C) ii and iv only
D) iii and v only

2. If one operand of the + operator is a string, it converts the other one to a ………..
A) String
B) TypeError
C) Undefined
D) Number

3. The ……………… operator converts its operand to a Boolean and negates it.
A) +
B) –
C) !
D) !!

4. The ……………… method defined by the number class accepts an optional argument that specifies a radix, or base for the conversion.
A) toRadix( )
B) toBase( )
C) toString( )
D) toBase10( )

5. ………………. converts a number to a string with a specified number of digits after the decimal point.
A) toInt( )
B) toFixed( )
C) toString( )
D) toPrecision( )

6. …………… converts a number to a string with the number of significant digits you specify.
A) toInt( )
B) toFixed( )
C) toString( )
D) toPrecision( )

7. ……………… accepts an optional second argument specifying the radix of the number to be parsed.
A) ParseFloat( )
B) ParseInt( )
C) ParseNumber( )
D) ParseString( )

8. While using parseInt( ) and parseFloat( ), if the first nonspace character is not a part of a valid numeric literal, they return ………….
A) undefined
B) infinity
C) NaN
D) zero

9. The global function parseInt(“11”,2) in JavaScript returns which of the following values.
A) 2
B) 3
C) 11
D) 13

10. The global function parseFloat(“.1”) returns which of the following values.
A) 1
B) 0.1
C) 0
D) NaN

11. Wrapper classes define ………………. methods that return the wrapped primitive value.
A) ValueOf( )
B) ParseInt( )
C) ParseNumber( )
D) ParseString( )

12. If the object has a ………………. method that returns a primitive value, JavaScript converts that primitive value, JavaScript converts that primitive value to a number and returns the result.
A) ValueOf( )
B) ParseInt( )
C) ParseNumber( )
D) ParseString( )

13. If the object has a ……………. method that returns a primitive value, JavaScript converts and returns the value.
A) toInt( )
B) toFixed( )
C) toString( )
D) toPrecision( )

14. State whether the following statements about type conversion in JavaScript are True.
i) Array to number conversion relies on the toString( ) method.
ii) The + operator in JavaScript performs numeric addition but not string concatenation
iii) With toString( ) method, empty arrays convert to the empty string.
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii

15. …………….. object was created, while converting empty string ” ” to an object in JavaScript.
A) new string (empty)
B) new string(” “)
C) string(” “)
D) new string( )

16. While converting the value to a number, if it cannot perform a meaningful conversion will result ………..  value.
A) Infinity
B) NaN
C) undefined
D) TypeError

17. In JavaScript arithmetic, if var n=1-“x”; what will be the result of  n + “objects”
A) NaN objects
B) n objects
C) NaN
D) objects

18.In JavaScript, if var a=[ ]; and var b=a; what will be the result of a = = = b.
A) False
B) True
C) Undefined
D) NaN

Answers

1. C) ii and iv only
2. A) String
3. C) !
4. C) toString( )
5. B) toFixed( )
6. D) toPrecision( )
7. B) ParseInt( )
8. C) NaN
9. B) 3
10. B) 0.1
11. A) ValueOf( )
12. A) ValueOf( )
13. C) toString( )
14. C) i and iii only
15. B) new string(” “)
16. B) NaN
17. A) NaN objects
18. B) True

Read Next:Top 20 MCQ On JavaScript Expressions And Operators

Author

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

Comments are closed.