Home  >  Article  >  Web Front-end  >  Detailed explanation of examples of reference types in javascript

Detailed explanation of examples of reference types in javascript

零下一度
零下一度Original
2017-07-21 17:31:041129browse

Detailed explanation of examples of reference types in JavaScript

For us developers, it must be strange to have a reference type in JavaScript! Those are the basic packaging types: Boolean, Number, and String. This is not our fault, the main reason is that we don’t use these at all. These are automatically called within JavaScript. So, you might be a little confused. Next, let me give you an example.

1 var s1 = "hello,world";2 var s2 = s1.substring(1);3 console.log(s2); //"ello,world"

Do you feel there is something wrong with the output of the above code? For a basic type of string s1, logically there is no method, so why does the program not report an error? In fact, when the program executes to the second line, the background goes through such a process. The code is written as follows:

var s1 = new String("hello,world");var s2 = s1.substring(1);//等实例上调用指定方法后立即销毁这个实例,整个过程都在后台发生,我们并没有什么察觉

Just understand this process. We generally don't use these packaging classes.

The next thing to talk about is the last reference type, the single built-in object. Such objects include: Global object and Math object.

Global object is a global object. All properties and methods that do not belong to any other object are ultimately its properties and methods! It also includes many other methods. ECMAScript does not indicate how to access the Global object directly. But in the browser, the global object is implemented as part of the window object. In other words, window is the global object in the browser.

The Math object provides a large number of mathematical calculation methods to assist us in completing complex mathematical calculation tasks. For example: random number random(), absolute value abs(), maximum value max(), minimum value min()....

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

Statement:
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