当前位置:网站首页>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
边栏推荐
- C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.3 什么是声明,什么是定义
- [Evaluation model] Topsis method (pros and cons distance method)
- 读者让我总结一波 redis 面试题,现在肝出来了
- The difference between px, em, and rem
- 有趣的 Kotlin 0x0E:DeepRecursiveFunction
- 触觉智能分享-SSD20X实现升级显示进度条
- 8款最佳实践,保护你的 IaC 安全!
- 深度学习21天——卷积神经网络(CNN):实现mnist手写数字识别(第1天)
- canal实现mysql数据同步
- 4.1 声明式事务之JdbcTemplate
猜你喜欢

编程大杂烩(三)

CentOS7 —— yum安装mysql

少年成就黑客,需要这些技能

入坑软件测试的经验与建议

Dynamic programming of the division of numbers
![[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection](/img/1a/b3bdf9b62c82b0fc4d913045981d94.png)
[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection

字节最爱问的智力题,你会几道?

败给“MySQL”的第60天,我重振旗鼓,四面拿下蚂蚁金服offer

Resolved error: npm WARN config global `--global`, `--local` are deprecated

MySQL数据库面试题总结(2022最新版)
随机推荐
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.1 数组并非指针
Programming hodgepodge (4)
leetcode 12. Integer to Roman numeral
有趣的 Kotlin 0x0E:DeepRecursiveFunction
FPGA学习笔记——知识点总结
QT 如何识别文件的编码格式
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.5 数组和指针的其他区别
There is an 8 hour difference between the docker installation of mysql and the host.
【评价类模型】Topsis法(优劣解距离法)
部署LVS-DR群集【实验】
npm init [email protected] 构建项目报错SyntaxError: Unexpected token ‘.‘解决办法
C专家编程 第5章 对链接的思考 5.4 警惕Interpositioning
Will the 2023 PMP exam use the new version of the textbook?Reply is here!
败给“MySQL”的第60天,我重振旗鼓,四面拿下蚂蚁金服offer
MySql数据恢复方法个人总结
力扣:63. 不同路径 II
idea设置识别.sql文件类型以及其他文件类型
Use Patroni callback script to bind VIP pit
你以为border-radius只是圆角吗?【各种角度】
8款最佳实践,保护你的 IaC 安全!