String
We know that javascript includes: number, string, boolean, null, undefined primitive types and Object types.
In my understanding, method attributes should be something that objects can have.
var str="hello,world";var s=str.subString(,);//ellalert(typeof(str)+":"+typeof(s));//string:string
Judging from the above return type, str is of type string.
Let's see how to declare a string using a global object.
var c=new String(str);alert(typeof(c));//Object<br>alert(c.toString());//hello,world
Then can I think: When I process strings,
The javascript compiler first uses new String(str); to form an object. Then call its processing method, and then use the toString() method to return a string.
Creation and destruction of temporary objects
From the example above I know that javascript will create temporary objects when processing strings, number,boolean and then destroy them.
var a = "hello,world";var c = new String(a); //A string object was created. c.len = ;alert(typeof (c));//object;alert(c.len);//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
The compiler has no errors because the created temporary object was destroyed after operation.
== and ===
a==c ;//true;a===c;//false; String and object are not equal.
The above is the relevant knowledge about where the JavaScript method comes from that the editor introduces to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!