Friday, December 27, 2013

Global



Properties

Methods
Description
infinity
A numeric value that represents positive/negative infinity.
Example:
var x = 1.7976931348623157E+10308; // Infinity
var y = -1.7976931348623157E+10308;// -Infinity
NaN
"Not-a-Number" value.
Example:
var a = isNaN(123);    //false
var b = isNaN(-1.23);  //false
var c = isNaN(5-2);    //false
var d = isNaN(0);              //false
var e = isNaN("Hello");   //true
var f = isNaN("2005/12/12");  //true
var g = isNaN();       //true
var h = isNaN('45');  //false
undefined
Indicates that a variable has not been assigned a value.
Example:
var x;
if (x===undefined)  //or x==undefined
  {
  txt="x is undefined";
  }
else
  {
  txt="x is is defined";
  }
alert(txt);  //returns: x is undefined


var x;
if (x===””)  //or x==””
  {
  txt="x is undefined";
  }
else
  {
  txt="x is is defined";
  }
alert(txt);  //returns: x is defined


JavaScript Global Functions

Methods

Methods
Description
decodeURI()
Encodes a URI.
Decodes a URI component.
encodeURI()
Encodes a URI.
This function encodes special characters, except: , / ? : @ & = + $ # (Use encodeURIComponent() to encode these characters).

var uri = "my test.asp?name=ståle&car=saab";
var res = encodeURI(uri);
alert(res);// my%20test.asp?name=st%C3%A5le&car=saab
encodeURIComponent()
Encodes a URI component.

var uri = "http://w3schools.com/my test.asp?name=ståle&car=saab";
var res = encodeURIComponent(uri);
alert(res);
//http%3A%2F%2Fw3schools.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab



eval()
Evaluates a string and executes it as if it was script code.

Example:
var x = 10;
var y = 20;
var a = eval("x*y");  // 200
var b = eval("2+2");  // 4
var c = eval("x+17"); // 27

isFinite()
Determines whether a value is a finite, legal number.

Example:
var a = isFinite (123);             // true
var b = isFinite (-1.23);           // true
var c = isFinite (5-2);             // true
var d = isFinite (0);              // true
var e = isFinite ("Hello");        // false
var f = isFinite ("2005/12/12");   //false
var g = isFinite ();              //false
var h = isFinite ('45');           //true
var g = isFinite(false);          //true
var h = isFinite(true);          //true

isNaN()
Determines whether a value is an illegal number.

Example:
var a = isNaN(123);    //false
var b = isNaN(-1.23);  //false
var c = isNaN(5-2);    //false
var d = isNaN(0);              //false
var e = isNaN("Hello");   //true
var f = isNaN("2005/12/12");  //true
var g = isNaN();       //true
var h = isNaN('45');  //false

Number()
Converts an object's value to a number.

Example:
var test1 = new Boolean(true);
var test2 = new Boolean(false);
var test3 = new Date();
var test4 = new String("999");
var test5 = new String("999 888");

var a = Number(test1); //1
var b=  Number(test2); //0
var c = Number(test3); // 1388144600499
var d = Number(test4); // 999
var e=  Number(test5); // NaN

parseFloat()
Parses a string and returns a floating point number.

Example:
var a = parseFloat("10");        //10
var b = parseFloat("10.00");     //10
var c = parseFloat("10.33");     //10.33
var d = parseFloat("34 45 66");  //34
var e = parseFloat("   60   ");  //60
var f = parseFloat("40 years");  //40
var g = parseFloat("He was 40"); //NaN

parseInt()
Parses a string and returns an integer.

Example:
var a = parseInt("10");         //10
var b = parseInt("10.00");      //10
var c = parseInt("10.33");      //10
var d = parseInt("34 45 66");   //34
var e = parseInt("   60   ");   //60
var f = parseInt("40 years");   //40
var g = parseInt("He was 40");  // NaN
var h = parseInt("10",10);      / / 10
var i = parseInt("010");        // 10
var j = parseInt("10",8);       // 8
var k = parseInt("0x10");       // 16
var l = parseInt("10",16);      // 16

String()
Converts an object's value to a string.

Example:
var test1 = new Boolean(1);
var test2 = new Boolean(0);
var test3 = new Boolean(true);
var test4 = new Boolean(false);
var test5 = new Date();
var test6 = new String("999 888");
var test7 = 12345;


var a = String (test1); // true
var b=  String (test2); // false
var c = String (test3); // true
var d = String (test4); // false
var e=  String (test5); // Fri Dec 27 2013 17:28:40 GMT+0530 (India Standard Time)
var f=  String (test5); // 999 888
var g=  String (test5); // 12345

escape()
Deprecated in version 1.5. Use encodeURI() or encodeURIComponent() instead.
unescape()
Deprecated in version 1.5. Use decodeURI() or decodeURIComponent() instead.

No comments:

Post a Comment