ValueOf functions and toString methods in JavaScript: _ javascript skills

Source: Internet
Author: User
Basically, all JS data types have the valueOf and toString methods, except null. These two solutions solve the problem of javascript value calculation and display. This article will introduce in detail. If you need them, you can refer to the valueOf Function Method in JavaScript to return the original value of the specified object. Usage:
Object. valueOf () object is a required parameter and is an inherent JScript object.
The valueOf method definition of each inherent JavaScript Object is different.
Object Return Value
Array Elements of the array are converted into strings separated by commas (,) and connected together. Its operations are the same as those of Array. toString and Array. join.
Boolean Boolean value.
Date The storage time is the number of milliseconds from midnight, January 1, January 1, 1970 in UTC.
Function Function itself.
Number Numeric value.
Object Object. This is the default situation.
String String value.

Math and Error objects do not have the valueOf method.

Basically, all JS data types have the valueOf and toString methods, except null. They solve the javascript value calculation and display problems.
ValueOf () method of JavaScript
The valueOf () method returns the original value of a Boolean object.
Use booleanObject. valueOf (). The return value is the original Boolean value of booleanObject. If the object that calls this method is not Boolean, an exception TypeError is thrown.

The Code is as follows:


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.