当前位置:网站首页>JS basics - forced type conversion (error-prone, self-use)
JS basics - forced type conversion (error-prone, self-use)
2022-08-04 05:30:00 【ᥬ little moon】
1. Convert null and undefined to strings:
① Use the toString function: null and undefined have no tostring() method, and report an error directly
② Use String functions:
'null', 'undefined'
2. Convert other types to Number:
Use the Number function:
① number string --> number
② number + non-numeric string --> NAN
③ empty string --> 0
④ null --> 0
⑤ undefined --> NAN
⑥ true --> 1
⑦ false --> 0
Use the parseInt / parseFloat functions (specifically to convert strings):
① String --> Read the part of numbers from left to right, and stop when the part that is not a number is encountered.
② Non-string --> Convert it to a string and then operate:
- true -->NAN
Tips: parseInt has two parameters, the first parameter is the number to be converted, and the second parameter is the base to be converted.
3, base:
Starting with 0x: hexadecimal
- 0x16
Starting with 0: hexadecimal
- 070
Starting with 0b: binary
- 0b10
4. Convert other types to Boolean:
Use Boolean functions:
① Numbers: Except 0 and NAN are false, the rest are true
② String: Except the empty string is false, the rest are true
③ null: false
④ undefined: false
⑤ Object: true
边栏推荐
- 有趣的 Kotlin 0x0E:DeepRecursiveFunction
- 关于yolo7和gpu
- DP4398:国产兼容替代CS4398立体声24位/192kHz音频解码芯片
- 注意!软件供应链安全挑战持续升级
- C Expert Programming Chapter 5 Thinking about Linking 5.1 Libraries, Linking and Loading
- What is the salary of a software testing student?
- 你以为border-radius只是圆角吗?【各种角度】
- day13--postman接口测试
- 在被面试官说了无数次后,终于潜下心来整理了一下JVM的类加载器
- string类简介
猜你喜欢

The symbol table

Tactile intelligent sharing - SSD20X realizes upgrade display progress bar

Performance testing with Loadrunner

There is an 8 hour difference between the docker installation of mysql and the host.

关于yolo7和gpu

leetcode 12. 整数转罗马数字

DP4398:国产兼容替代CS4398立体声24位/192kHz音频解码芯片

Shocked, 99.9% of the students didn't really understand the immutability of strings

C语言 -- 操作符详解

擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
随机推荐
day13--postman接口测试
MySQL数据库面试题总结(2022最新版)
Gartner 权威预测未来4年网络安全的8大发展趋势
C专家编程 第5章 对链接的思考 5.1 函数库、链接和载入
【SemiDrive源码分析】【MailBox核间通信】47 - 分析RPMSG_IPCC_RPC 方式 单次传输的极限大小 及 极限带宽测试
As soon as flink cdc is started, the CPU of the source Oracle server soars to more than 80%. What is the reason?
字节最爱问的智力题,你会几道?
FPGA学习笔记——知识点总结
8大软件供应链攻击事件概述
力扣:509. 斐波那契数
MySQL日志篇,MySQL日志之binlog日志,binlog日志详解
Will the 2023 PMP exam use the new version of the textbook?Reply is here!
【流程图】
C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.5 Other Differences Between Arrays and Pointers
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.2 Why does my code not work
sql server如何得到本条记录与上一条记录的差异,即变动值
C Expert Programming Chapter 5 Thinking about Linking 5.2 Advantages of Dynamic Linking
【评价类模型】Topsis法(优劣解距离法)
使用Patroni回调脚本绑定VIP的坑
8、自定义映射resultMap