The JavaScript Global Object: Explained and Demystified
The JavaScript global object is a collection of properties, functions, and objects that can be accessed globally without the need for a specific namespace. In this blog post, we will delve into the details of the global object and explore its various components.
Properties:
Infinity
: Represents the value infinity in JavaScript. It can be positive (Infinity
) or negative (-Infinity
).NaN
(Not a Number): Used to represent an invalid numeric operation. It is returned when performing operations such as zero divided by zero or invalidparseInt()
operations.undefined
: Holds the primitive valueundefined
and is returned when a function does not specify a return value.
Functions:
decodeURI()
: Performs the opposite operation ofencodeURI()
, decoding a URI component.decodeURIComponent()
: Performs the opposite operation ofencodeURIComponent()
, decoding a URI component.encodeURI()
: Encodes a complete URL, except for characters that have a special meaning in a URI.encodeURIComponent()
: Encodes a portion of a URI, except for characters that have a special meaning in a URI.eval()
: Evaluates a string of JavaScript code, but it is rarely used due to security concerns.isFinite()
: Returns true if the passed value is a finite number.isNaN()
: Returns true if the passed value isNaN
.parseFloat()
: Converts a string into a floating-point number, retaining the decimal part.parseInt()
: Converts a string into an integer, with a radix specified as the second parameter.
Objects:
Array
: Represents an array of elements.Boolean
: Represents a boolean value (true
orfalse
).Date
: Represents a date and time.Function
: Represents a function.JSON
: Provides methods for working with JSON data.Math
: Provides mathematical functions and constants.Number
: Represents a numeric value.Object
: Represents an object.RegExp
: Represents a regular expression pattern.String
: Represents a sequence of characters.Symbol
: Represents a unique identifier.
Errors:
Error
EvalError
RangeError
ReferenceError
SyntaxError
TypeError
URIError
By understanding the JavaScript global object and its components, you can leverage its properties, functions, and objects to enhance your JavaScript programming. Remember to use caution when utilizing certain functions like eval()
due to potential security risks.
Tags: JavaScript, global object, properties, functions, objects