JavaScript's built-in object's global object

Source: Internet
Author: User

The built-in objects are defined as:

Provided by the JavaScript implementation and not created by yourself, these objects already existed before the ECMAScript program was executed.

This means that developers do not have to instantiate the built-in objects as they are already instantiated.

JavaScript defines only two built-in objects: Global and Math.


A global (Global) object:

A special object in Javacript because this object does not exist. Properties and methods that are not part of any other object in JavaScript belong to its properties and methods.

So, in fact, there are no global variables and global functions; all variables and functions defined at the global scope are properties and methods of the Globals object.

Because JavaScript does not define how to call the Global object, the global. property or Global. Method () is not valid. (The Web browser implements Global as part of the Window object)

    var box = +;     // alert (global.box);//Will error    alert (window.box);  // you can use window to invoke

The Global object has some built-in properties and methods:

1.URI Encoding Method:

The URI encoding can encode the link for sending to the browser. They replace all invalid characters with special UTF-8 encoding, allowing the browser to accept and understand them.

Special characters that belong to a URI are not encoded, such as colons, forward slashes, question marks, and # numbers

encodeURI ()

var box = '//lee lee ';     // only encoded in Chinese the     result is this//lee%20%e6%9d%8e

encodeURIComponent () encodes any non-standard characters it discovers

   var box = '//lee lee ';      // special characters and Chinese encoded the    result is this%2f%2flee%20%e6%9d%8e

Because encodeURIComponent () encoding is more thorough than encodeuri () encoding, generally speaking encodeuricomponent () is used more frequently.

2.URI Decoding Method:

After the URI encoding is used, it can be decoded.

decodeURI () to decode

var box = '//lee lee ';     // Coding     alert (box1);    Alert (decodeURI (box1)); // decoding

decodeURIComponent () to decode

 var   Box2  =   '   

3.eval () Method:

The main role of a string parser, he only accepts a parameter, and this parameter is to execute the JavaScript code string. (That is, JavaScript code can be parsed)

    Eval (' var box = + ');     // parse the string code    alert (box);                //  -    // Ibid .             eval (// function can also    alert (box ());

The eval () method is very powerful, but also very dangerous. It must therefore be used with extreme caution. Especially in the case of user input data, it is very likely to lead to the security of the program, such as code injection and so on.

4.parseInt () method: returns the integer converted from a string

var str = "123";     // parse from the beginning until it cannot be resolved    document.write (parseint (str) + "<br/>");    document.write (parseint ("+") + "<br/>");    document.write (parseint ("100abc") + "<br/>");    document.write (parseint ("abc100") + "<br/>");    document.write (parseint ("100abc0") + "<br/>");         // the first argument is converted by the second argument, and the second argument is the binary number, such as the 2-binary 8-binary 16    -Binary document.write ("parseint", 2) + "<br/>");

parsefloat () method: similar to parseint

5.isNaN Method:

Returns a Boolean value that indicates whether the supplied value is a reserved value, NaN (not a number).

If the value is NaN, then the isNaN function returns true , otherwise false is returned.

The typical case for using this function is to check the return values of the parseint and parsefloat methods.

Alert (IsNaN ());    Alert (IsNaN ("Jaav"));   // true     alert (IsNaN (NaN));    Alert (IsNaN (parseint ("123lee")); // The result of parseint ("123lee") is 123, so isNaN (123) is False    Alert (IsNaN (parseint ("lee123")); // The result of parseint ("lee123") is NaN, so isNaN (Nan) is true

6.Global Object Properties:

The Global object contains attributes: Undefined, NaN, object, Array, Function, and so on.

    // returns the constructor function     alert (undefined);    alert (Object);

7.window objects:

Global has no direct access, and a Web browser can use the Window object to achieve a global access.

// returns the constructor function

JavaScript's built-in object's global object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.