• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 3. The JavaScript Language: Loop... > The JavaScript Built-in Functions

The JavaScript Built-in Functions

The last topic I’ll take a look at in our coverage of JavaScript functions gives us a look at the functions that are already built in to JavaScript, and are available anywhere in your code. (In fact, these built-in functions are sometimes called global functions.) Table 3.15 lists these functions.

Table 3.15. JavaScript’s Global Functions
Function NS2 NS3 NS4 NS6 IE3a IE3b IE4 IE5 IE5.5 IE6
decodeURI    x     x x
   Decodes a uniform resource identifier (URI). URIs are encoded for use with browsers—for example, a space is encoded as a hex value, %20. This function decodes encoded URIs, substituting, for example, spaces for %20.
   Syntax: decodeURI("URI")
   Returns: String
decodeURIComponent     x    x x
   Decodes a URI component. The same as decodeURI, except that this function works on components, which are parts of complete URIs.
   Syntax: decodeURI("URIComponent")
   Returns: String
encodeURI    x     x x
   Encodes a URI for use in a browser, converting, for example, spaces into their hex equivalent, %20. More recent than the escape function, does not encode these characters—; / : @ & = + $ , - _ . ! ~ * ‘ ( ) #—because these characters are now considered legal in URIs.
   Syntax: encodeURI("Text")
   Returns: String
encodeURIComponent    x     x x
   Encodes a URI component for use in a browser. The same as encodeURI, except that this function works on URI components, which are parts of complete URIs.
   Syntax: encodeURI("Text")
   Returns: String
escape x x x x x x x x x x
   “Escapes” a string into a URI that can be used in a browser. This function converts nearly all nonalphanumeric characters to their escaped version. (For example, spaces are converted to hex %20.) Performs more escaping than the more modern encodeURI.
   Syntax: escape("Text")
   Returns: String
eval x x x x x x x x x x
   Evaluates a JavaScript expression. See below for more information.
   Syntax: eval("string")
   Returns: Object reference
isFinite x x x x x x x x x x
   Checks whether an expression yields a number outside the maximum or minimum possible values JavaScript can store. Returns false if the expression’s value is outside the maximum or minimum possible values.
   Syntax: isFinite(number)
   Returns: Boolean
isNaN x x x x x x x x x x
   Checks whether a value is a valid number (isNaN stands for Is Not a Number) and returns true if the value passed to it is not a number. Useful for checking the results of parseInt and parseFloat.
   Syntax: isNaN(value)
   Returns: Boolean
Number   x x   x x x x
   Converts a string to an integer or a floating-point number, as appropriate.
   Syntax: Number("string")
   Returns: Number
parseFloat x x x x x x x x x x
   Converts a string to a floating-point number. Syntax: parseFloat("string")
   Returns: Number
parseInt x x x x x x x x x x
   Converts a string to an integer. Can also take a base (also called a radix) to use when converting—for example, parseInt(myString, 16) creates a hexadecimal (base 16) value.
   Syntax: parseInt("string" [, radix])
   Returns: Number
toString x x x x x x x x x x
   This is a method of every JavaScript and DOM object, and is intended to convert the object into a string representation as meaningfully as it can. Can also take a radix if needed.
   Syntax: toString("string" [, radix])
   Returns: String
unescape x x x x x x x x x x
   Converts an escaped URI into its unescaped version, the counter-part of the escape function.
   Syntax: unescape("URI")
   Returns: String
unwatch   x x      
   Directs an external debugger not to watch a particular property anymore.
   Syntax: unwatch(property)
   Returns: Nothing
watch   x x      
   Directs an external debugger to watch the value of a particular property.
   Syntax: watch(property, debugHandler)
   Returns: Nothing



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint