Preface: Reference values (objects) are instance objects of a specific reference type, such as 1. DateThe following three methods return timestamps in milliseconds. let t1 = Date.UTC(2020, 11, 7, 22,14) let t2 = Date.parse("5/23/2020") let t3 = Date.now() The parameter format received by parse can be: let t4 = new Date() let t5 = new Date(2020, 11, 7) // Month starts at 0 let t6 = new Date("5/23/2020") The 2. RegExp In let express = /pattern/flags;
In addition to expressing regular expressions in literal form, you can also create them using the RegExp constructor. let p1 = /[cb]at/i let p2 = new RegExp("[cb]at", "i") The two are equivalent. The let p1 = /[cb]at/i let text = "hello cat bat nihao" matches = p1.exec(text) console.log(matches.index) console.log(matches.input) console.log(matches[0]) //cat If the regular expression matches, the returned let p1 = /([cb]a(t))/i console.log(matches[0]) //cat console.log(matches[1]) //cat console.log(matches[2]) //t The test method returns a Boolean value that determines whether the string matches the regular expression. let matched = /\d+/g.test("13") console.log(matched) //true Here we need to explain the function of the g in let p1 = /[cb]at/gi let text = "hello cat bat nihao" console.log(p1.exec(text)) // ["cat", index: 6, input: "hello cat bat nihao", groups: undefined] console.log(p1.exec(text)) //["bat", index: 10, input: "hello cat bat nihao", groups: undefined] In the string text, there are actually two places that match the regular expression, but when we call In addition, strings provide many methods that accept regular expressions as parameters, which can be used for regular expression matching, string replacement, searching for specified strings, or grouping. 3. Original packaging type The three reference types The original packaging type has the following characteristics, which can be noted: let s1 = "hello" s1.name = "sex" console.log(s1.name) //undefined Why is let s1 = "hello" s1 = new String(s1) s1.name = "sex" console.log(s1.name) For let value = 25 let number = Number(value) obj = new Number(value) console.log(typeof number) //number console.log(typeof obj) //object console.log(number instanceof Number) //false The original value is not an instance object of any type console.log(obj instanceof Number) //true
let num = 10.007 console.log(num.toFixed(2)) //10.01 For String, a lot of methods for operating strings are provided, and you can type them all manually according to the examples. 4. Other built-in objects Variables under the global scope, some commonly used individual functions such as url = "http://www.baidu.com/vue.js" console.log(encodeURI(url)) //http://www.baidu.com/vue.%20js console.log(encodeURIComponent(url)) // http%3A%2F%2Fwww.baidu.com%2Fvue.%20js The corresponding decoding functions are In the browser, var name = "zhang" console.log(window.name) Math objectconsole.log(Math.max(1,2,3,4)) // maximum valueconsole.log(Math.min(3,3,4)) // minimum valueconsole.log(Math.ceil("1.2")) // round upconsole.log(Math.floor(3.3)) // round downconsole.log(Math.round(3.6)) // round up This is the end of this article about basic reference types in JavaScript advanced programming. For more relevant content about basic reference types in JavaScript, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Talking about the practical application of html mailto (email)
>>: Analysis of the advantages and disadvantages of MySQL stored procedures
Table of contents 1. The magical extension operat...
Problem Reproduction When using HTML for editing,...
HTTP Header Explanation 1. Accept: Tells the web s...
Table of contents 1. Introduction 2. Advantages 3...
Table of contents Creating Arrays in JavaScript U...
Table of contents 1. Count data is lost Solution ...
This article shares the specific implementation c...
This article shares the specific code of Vue to a...
Table of contents 0x01. Install the Pagoda Panel ...
This article uses examples to explain the princip...
Comprehensive understanding of html.css overflow ...
According to the principles of W3C, each start tag...
Environment: VMware VCSA 6.7 (VMware-VCSA-all-6.7...
This article shares the specific code for JavaScr...
Problems: After adding the -v parameter to docker...