Common methods for Global, Math, and date objects in JavaScript

Source: Internet
Author: User

The common methods of global, Math, and date types in JavaScript are as follows:

1 /*2 The global object in JS is a nonexistent object, and the method inside it can call3 Common methods:4 1 encodeURI Convert the URI byte, do not change the special symbol, not commonly used5 2 encodeURIComponent Convert byte code to URI, convert all symbols commonly used6 3 decodeURI decoding7 4 decodeuricomponent decoding8 5 eval Pass in a string as a JS script to execute9 6 parseint Strings converted to integersTen 7 parsefloat string converted to decimal One 8 IsNaN Not number type returns True A 9 Escape to string transcoding with Chinese - Unesacape string decoding with Chinese characters - */ the //1 encodeURI Convert the URI byte, do not change the special symbol, not commonly used - //2 encodeURIComponent Convert byte code to URI, convert all symbols commonly used - //3 decodeURI decoding - //4 decodeuricomponent decoding + varURI = "Http://www.baidu.com cn"; - varUri1 =encodeURI (URI); + varUri2 =encodeURIComponent (URI); A alert (URI1); at alert (URI2); - alert (decodeURI (URI1)); - alert (decodeURIComponent (URI2)); -  -  - //5 eval Pass in a string as a JS script to execute in varstr = "var a = 10;"; - eval (str); to alert (a); + varstr1 = "{name: ' Z3 ', age:18}"; - varobj = eval ("(" +str1+ ")");//enclosed in parentheses represents an immediate execution of a code block, and the execution result is assigned to obj as an object. the alert (obj.name); *  $ Panax Notoginseng  //6 parseint -  //7 parsefloat theAlert (parseint ("10")); +Alert (parsefloat ("10.1")); A  the  + //9 Escape with Chinese transcoding - //Ten Unesacape with Chinese decoding $ varstr = Escape ("haha"); $ alert (str); - Alert (unescape (str)); -  the  - Wuyi  the  -  Wu //Math.random () generates a [0,1] random number - //Math.ceil (num) rounding up About //Math.floor (num) rounding down $ //math.round (num) rounding -  -  -  A varDate =NewDate (); + //alert (date); the //Date datetime = new Date () - //method to get the current time $ varYear =date.getfullyear (); the //alert (year); the varmonth = Date.getmonth () +1 ; the //alert (month); the varTdate = Date.getdate ();//Date - //alert (tdate); in varHours = Date.gethours ();//Get Hours the //alert (hours); the varmin = Date.getminutes ();//minutes About //alert (min); the varSEC = Date.getseconds ();//seconds the //alert (sec); the varDay = Date.getday ();//Day of the week + //alert (day); -  the //alert ("Today is" +year+ "year" +month+ "month" +day+ "Day, Week" +day + "," + hours+ "point" +min+ "sub" +sec+ "Seconds");Bayidocument.write ("Today is" +year+ "year" +month+ "month" +day+ "Day, Week" +day + "," + hours+ "point" +min+ "minute" +sec+ "seconds" ); the             

Common methods for Global, Math, and date objects in JavaScript

Related Article

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.