Home > Web Front-end > JS Tutorial > body text

What are reference types in javascript

醉折花枝作酒筹
Release: 2023-01-06 11:17:27
Original
7268 people have browsed it

The reference types in JavaScript are: 1. Object type; 2. Function type; 3. Array type; 4. RegExp type; 5. Date type; 6. Basic packaging type; 7. and single built-in type. Object(Global, Math).

What are reference types in javascript

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, Dell G3 computer.

1. Object type

Object is also the most commonly used type in ECMAScript

2.Array type

Detect array if (value instanceof Array) { }

Conversion method, all objects have toLocaleString(), toString() and valueOf() methods

Stack method push () and pop() shift() and push() unshift() and pop()

Reordering method reverse() and sort()

Operation method concat() slice() splice()

Position methods indexOf() and lastIndexOf()

Iteration method every() filter() forEach() map() some()

Merge method reduce () and reduceRight()

3. Date type

var now = new Date();

Create a date based on a specific date and time Objects Date.parse() and Date.UTC().

Inherited methods toLocaleString(), toString() and valueOf()

Date formatting methods toDateString() toTimeString() toLocaleDateString() toLocaleTimeString() toUTCString()

Date/time component method getTime().............getMilliseconds().....

4, RegExp type

ECMAScript supports regular expressions through the RegExp type.

var expression = / pattern / flags ;

g: Indicates a global pattern, that is, the pattern will be applied to all strings, rather than immediately when the first match is found

Stop;

i: Indicates case-insensitive mode, that is, ignoring the case of patterns and strings when determining matches;

m : Indicates multiline mode, that is, when reaching the end of a line of text, it will continue to search whether there is an item matching the pattern

in the next line.

RegExp instance attribute

global: Boolean value, indicating whether the g flag is set.

ignoreCase: Boolean value, indicating whether the i flag is set.

lastIndex: Integer, indicating the character position to start searching for the next match, starting from 0.

multiline: Boolean value indicating whether the m flag is set.

source: The string representation of the regular expression, returned in literal form rather than the string pattern passed in the constructor.

RegExp instance method

exec()

5. Function type

Each function is an instance of the Function type. And they all have the same properties and methods as other reference types

Inside the function, there are two special objects: arguments and this.

Because the value of this is not determined before the function is called, this may refer to different objects during code execution. When called in the global scope, this refers to the global object window;

Each function contains two properties: length and prototype.

6. Basic packaging types

In order to facilitate the operation of basic type values, ECMAScript also provides 3 special reference types: Boolean, Number and

String.

In addition to the inherited methods, the Number type also provides some methods for formatting numeric values ​​into strings.

Among them, the toFixed() method will return the string representation of the value according to the specified decimal places, for example:

var num = 10;

alert(num.toFixed( 2)); //"10.00"

Another method that can be used to format values ​​is toExponential(), which returns the value expressed in exponential notation (also called e notation)

The string form of a numerical value

The two methods used to access specific characters in a string are: charAt() and charCodeAt();

String operation methods: concat() slice() , substr() and substring() indexOf() and lastIndexOf() trim()

toLowerCase(), toLocaleLowerCase(), toUpperCase() and toLocaleUpperCase()

match() search( ) replace() split() localeCompare() fromCharCode()

alert(String.fromCharCode(104, 101, 108, 108, 111)); //"hello"

7. Single built-in object

ECMA-262 defines built-in objects as: “Objects provided by ECMAScript implementations that do not depend on the host environment

Global Object

Global (global) object can be said to be the most special object in ECMAScript, because no matter which angle you look at it,

This object is Exists. The Global object in ECMAScript is, in a sense, defined as an ultimate "catch-all object". In other words, properties and methods that do not belong to any other object are ultimately Its properties and methods. In fact, there is no full

Local variables or global functions; all properties and functions defined in the global scope are properties of the Global object. The functions

introduced earlier in this book, such as isNaN(), isFinite(), parseInt() and parseFloat(), are actually all methods of the Global

object. In addition to this, the Global object also contains some other methods.

1. URI encoding method

The encodeURI() and encodeURIComponent() methods of the Global object can encode URIs (Uniform Resource

Identifiers, universal resource identifiers). In order to be sent to the browser

2. eval() method

Math object

min() and max() methods Math.ceil() , Math.floor() and Math.round()

The Math object also contains other methods related to completing various simple or complex calculations

[Recommended learning:javascript advanced tutorial

The above is the detailed content of What are reference types in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template