Home > Web Front-end > JS Tutorial > How to use javascript type conversion_Basic knowledge

How to use javascript type conversion_Basic knowledge

WBOY
Release: 2016-05-16 17:01:07
Original
1054 people have browsed it

(1) Convert to string

Copy code The code is as follows:

X ' '
toString()
String()

Converting a function to a string usually involves outputting the function body, but you can override its toString method

(2) Convert to numbers

Copy code The code is as follows:

parseInt() ,parseFloat()

Use Number() without adding new in front, so it will be converted into an object.

Participate in mathematical operations (except addition)

X: Note that this is not addition

(3) Convert to Boolean value

Automatic conversion: If statements, ||, &&, ! and other logical judgment environments will automatically convert expressions into Boolean values ​​

Force conversion: use!!, use Boolean(), do not add new in front, so it will be converted into an object.

(4) Convert to object

Direct new object name

(5) Summary

Each type has: object name (variable to be converted) conversion method, as well as some independent skills.

JS type conversion, you can refer to the figure below:

How to use javascript type conversion_Basic knowledge
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