JS Built-in Objects Flashcards
What is the global object in JavaScript?
JavaScript provides a global object which has a set of properties, functions and objects that are accessed globally, without a namespace.
List the global properties in JavaScript.
Infinity, NaN, undefined
List the global functions in JavaScript.
decodeURI(), decodeURIComponent(), encodeURI(), encodeURIComponent(), eval(), isFinite(), isNaN(), parseFloat(), parseInt()
List the global objects in JavaScript.
Array, Boolean, Date, Function, JSON, Math, Number, Object, RegExp, String, Symbol, and errors.
What does Infinity represent in JavaScript?
Infinity in JavaScript is a value that represents infinity.
How do you get negative infinity in JavaScript?
To get negative infinity, use the – operator: -Infinity.
What values are equivalent to positive and negative infinity?
Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY
What happens when you add any number to Infinity, or multiply Infinity for any number?
It still gives Infinity.
What does NaN stand for?
Not a Number
What operations return NaN?
Operations such as zero divided by zero, invalid parseInt() operations, or other operations.
How do you check if a value evaluates to NaN?
You must use the isNaN() global function.
How do you check if a variable is undefined?
It’s common to use the typeof operator to determine if a variable is undefined.
What is the purpose of the decodeURI() function?
Performs the opposite operation of encodeURI()
What is the purpose of the decodeURIComponent() function?
Performs the opposite operation of encodeURIComponent()
What is the purpose of the encodeURI() function?
This function is used to encode a complete URL.
What characters does encodeURI() not encode?
It does encode all characters to their HTML entities except the ones that have a special meaning in a URI structure, including all characters and digits, plus those special characters: ~!@#$&*()=:/,;?+-_..
What is the purpose of the encodeURIComponent() function?
Instead of being used to encode an entire URI, it encodes a portion of a URI.
What characters does encodeURIComponent() not encode?
It does encode all characters to their HTML entities except the ones that have a special meaning in a URI structure, including all characters and digits, plus those special characters: _.!~*’()
What does the eval() function do?
This is a special function that takes a string that contains JavaScript code, and evaluates / runs it.
Why is the eval() function rarely used?
It can be dangerous.
What does the isFinite() function return?
Returns true if the value passed as parameter is finite.
What does the isNaN() function return?
Returns true if the value passed as parameter evaluates to NaN.
What is the purpose of the parseFloat() function?
Like parseInt(), parseFloat() is used to convert a string value into a number, but retains the decimal part.
What is the purpose of the parseInt() function?
This function is used to convert a string value into a number.