JavaScript Questions & Answers – Parsing Values using JavaScript – II

This set of JavaScript Multiple Choice Questions & Answers focuses on “Parsing Values using JavaScript – II”.

1. What is the purpose of the radix parameter in the parseInt() method?
a) Numeral system not to be used
b) Numeral system to be used
c) Conversion mode
d) Parsing mode
View Answer

Answer: b
Explanation: function parseInt() method parses a string and returns an integer. The radix parameter is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a decimal number.

2. What will be the radix value of the parseInt() method when the string begins with 0?
a) 6
b) 7
c) 8
d) 9
View Answer

Answer: c
Explanation: If the string begins with 0x, then the radix value will be 16. If the string begins with “0”, the radix is 8 (octal). This feature is deprecated.

3. What is the purpose of the method JSON.parse()?
a) Parses a string to integer
b) Parses a string to JSON
c) Parses a string from JSON to JSON2
d) Parses integer to string
View Answer

Answer: b
Explanation: The JSON.parse() method parses a string as JSON, optionally transforming the value produced by parsing. The function parseInt() method parses a string and returns an integer.
advertisement
advertisement

4. What is the return type of the method parseInt()?
a) String
b) Float
c) Integer
d) Date
View Answer

Answer: c
Explanation: The function parseInt() method parses a string and returns an integer. The method parseInt() returns an integer.

5. What are the parameters of the method JSON.parse()?
a) text
b) reviver
c) both text and reviver
d) object
View Answer

Answer: c
Explanation: The JSON.parse() method can optionally transform the result with a function. The parameters of the method JSON.parse() are :

  • text : The string to parse as JSON.
  • reviver : If a function, prescribes how the value originally produced by parsing is transformed, before being returned.

6. What will be the radix value of the parseInt() method when the string begins with any other value other than 0x and 0?
a) 8
b) 9
c) 10
d) 11
View Answer

Answer: c
Explanation: The radix value will be 10 when the string of the method parseInt() begins with any other value other than 0x and 0. If the string begins with 0x, then the radix value will be 16.

7. What kind of an exception will be thrown if the string to parse is not valid JSON?
a) SyntaxError
b) ArrayOutOfBoundException
c) Both SyntaxError and ArrayOutOfBoundException
d) Compilation error
View Answer

Answer: a
Explanation: The JSON.parse() method parses a string and returns a JavaScript object. The method JSON.parse()throws a SyntaxError exception if the string to parse is not valid JSON.
advertisement

8. Which of the following is a JavaScript Compressor?
a) Esprima
b) UgilifyJS
c) Acron
d) Compressify
View Answer

Answer: b
Explanation: UgilifyJS is a JavaScript compressor/minifier written in JavaScript. It also contains tools that allow one to automate working with JavaScript code.

9. What is the purpose of the UgilifyJS?
a) Exposes a simple API
b) Minification
c) Both Exposes a simple API and Minification
d) Compilation
View Answer

Answer: c
Explanation: UglifyJS is a JavaScript compressor/minifier written in JavaScript. UglifyJS2 is an excellent tool to help you minify your JavaScript! It’s a tried and tested tool, used by libraries such as jQuery.
advertisement

10. Which of the following is the fastest JavaScript parser?
a) JSLint
b) Esprima
c) Acron
d) Traceur
View Answer

Answer: c
Explanation: Acorn is a JavaScript parser written in JavaScript. : Acron is the fastest JavaScript parser written in JavaScript which takes only 96.9ms when compared to all the JavaScript parsers available. Acron is the fastest JavaScript parser written in JavaScript which takes only 96.9ms when compared to all the JavaScript parsers available.

Sanfoundry Global Education & Learning Series – Javascript Programming.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.