JavaScripture
Contribute via GitHub Feedback

JavaScript Global : Object

The following are properties of the global object. They can be accessed from anywhere without additional qualifiers.

Global Properties

Infinity : Number

Positive infinity.

Example:

Run

Results:

 

NaN : Number

Floating point Not a Number. Signifies an error in a calculation. NaN is never equal to another Number, even if it is NaN. To check if something is NaN, use isNaN().

Example:

Run

Results:

 

undefined : undefined

Returns the undefined type. This value signifies no value has been set on a property or that a method returned no value.

Example:

Run

Results:

 

Global Methods

decodeURI(encodedURI : String) : String

Returns a string that is the decoded version of encodeURI.

Example:

Run

Results:

 

decodeURIComponent(encodedURIComponent : String) : String

Returns a string that is the decoded version of encodeURIComponent.

Example:

Run

Results:

 

encodeURI(uri : String) : String

Returns a string that is the encoded version of uri.

Example:

Run

Results:

 

encodeURIComponent(component : String) : String

Returns an encoded version of component that is suitable as a uri parameter.

Example:

Run

Results:

 

eval(code : String) : Object

Treats code as JavaScript and executes it, returning the result.

Example:

Run

Results:

 

isFinite(x : Number) : Boolean

Returns true if x is not NaN, +Infinity, or -Infinity.

Example:

Run

Results:

 

isNaN(x : Number) : Boolean

Returns true if x is NaN. NaN is never equal to another Number, even if it is NaN, so you must use isNaN to check for NaN.

Example:

Run

Results:

 

parseFloat(str : String) : Number

Converts str into a floating point number.

Example:

Run

Results:

 

parseInt(str : String, [base : Number]) : Number

Converts str into an integral number. If base is not specified, parseInt will attempt to determine the base to use depending on the input. parseInt is more forgiving than Number(str) (or equivalently +str) in that it will ignore extra characters after the numeric portion of the string. If the first character is not a valid number in the specified base, parseInt will return NaN.

Example:

Run

Results: