Global properties and methods in JavaScript.
Some of the global object have static properties and methods that are accessed directly from the prototype as opposed to an instance. Since there are only a few, I will list them here:
Date.now(); //Mozilla only Date.parse(dateString); Date.UTC(year, month[, date[, hour[, min[, sec[, ms]]]]]); Math.PI; //etc, etc, because all members of Math are static! Number.MAX_VALUE; Number.MIN_VALUE; Number.NaN; Number.NEGATIVE_INFINITY; Number.POSITIVE_INFINITY; String.fromCharCode(num1, ..., numN);
JS has 3 top-level properties that are always available.
Implemented: JS 1.3; ECMA-262.
A numeric value representing infinity. Initially equivalent to Number.POSITIVE_INFINITY, but there is also Number.NEGATIVE_INFINITY.
Implemented: JS 1.3; ECMA-262.
A value representing Not-A-Number. Initially equivalent to Number.NaN. In pseudo-code: NaN <> NaN <> Number.NaN, so use isNaN() for comparison instead.
Implemented: JS 1.0; ECMA-262.
A variable that has not been assigned a value is of type undefined. EG:
var x; alert(x === undefined); //alerts true alert(typeof x == 'undefined'); //alerts true
These are global functions that are built into JavaScript and are not associated with any objects. The constructors of global objects (EG: String('hi');) are effectively global functions too. Some of the operators are effectively functions as well.
These functions are most often used for data going to or from an URL, URI, query string, etc.
Implemented: JS 1.5.
Undoes encodeURI().
Implemented: JS 1.5.
Undoes encodeURIComponent().
Implemented: JS 1.5.
Returns a string encoding all characters (including spaces) except for the following:
/ ? : @ & = + $ , ;A-Za-z0-9- _ . ! ~ * ' ( )#Characters are encoded in UTF-8 with 1-4 sequences of %XX where X is a hexadecimal digit.
Implemented: JS 1.5.
Like encodeURI() except that the parameter is a URI component (like user entered data), so it also encodes the URI reserved characters. EG:
encodeURI('http://fake.com?x='+'Thyme &time=again');
//http://fake.com?x=Thyme%20&time=again
encodeURIComponent('http://fake.com?x='+'Thyme &time=again');
//http%3A%2F%2Ffake.com%3Fx%3DThyme%20%26time%3Dagain
escape('http://fake.com?x='+'Thyme &time=again');
//http%3A//fake.com%3Fx%3DThyme%20%26time%3Dagain
Implemented: JS 1.0; JS 1.5 deprecated.
Returns a string encoding all characters (including spaces) except for:
A-Za-z0-9- _ . * @ + /Characters are encoded using 2 digit IETF escapes: %XX where X is a hexadecimal digit. This implies that it only handles a subset of Unicode characters. This is roughly equivalent to the Server.URLEncode() method of ASP, and the Escape() function of VBS.
So the problem with escape() is three-fold: An incomplete set of URI reserved characters, it doesn't escape all Unicode characters, and it doesn't distinguish between a URI component and a whole URI..
Implemented: JS 1.0; JS 1.5 deprecated.
Undoes escape(). Similar to the VBS Unescape() function. ASP does not have an equivalent method.
Implemented: JS 1.0; ECMA-262 except for the 2nd parameter
Takes a string and evaluates it as a JS expression, i.e. without reference to an object. If the optional 2nd parameter is provided, then the evaluation is restricted to the passed object. As of 2008, the 2nd parameter is only available in Mozilla. eval() is a potentially dangerous function and should be used cautiously and rarely. EGs:
str = "3 * x + 4"; x = 2; myValue = eval(str); //myValue is equal to 10. You could have done any number of things to get the value of 10. eval(new String("2 + 2")); //returns a string "2 + 2" eval("2 + 2"); //returns 4
Implemented: JS 1.3; ECMA-262.
Checks if a value is a finite number. If the number is NaN, positive infinity or negative infinity, then this method returns false, otherwise it returns true.
Implemented: JS 1.0; ECMA-262.
Checks if value is NaN. EG:
isNaN(NaN) //returns true isNaN("string") //returns true isNaN("12") //returns false isNaN(12) //returns false
Implemented: JS 1.0; ECMA-262.
Converts string to floating-point number. JS 1.0+.
Implemented: JS 1.0; ECMA-262.
Converts string to integer of an optionally specified radix or base. If the input string begins with "0x", the radix is 16 (hexadecimal). If the input string begins with "0", the radix is eight (octal). [This octal feature is deprecated in JS 1.5.] If the input string begins with any other value, the radix is 10 (decimal).
Implemented: JS 1.0; JS 1.4 deprecated.
Taints or marks a data element or script.
Implemented: JS 1.0; JS 1.4 deprecated.
Removes tainting from a data element or script.
Page Modified: (Hand noted: 2008-09-17 18:08:18Z) (Auto noted: 2008-09-17 21:51:18Z)