当前位置:网站首页>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
边栏推荐
- static在不同位置定义变量居然还有不同的含义?
- C Expert Programming Chapter 5 Thinking about Chaining 5.6 Take it easy --- see who's talking: take the Turning quiz
- 路网编辑器技术预研
- [Cocos] cc.sys.browserType可能的属性
- 数的划分之动态规划
- 商城系统APP如何开发 都有哪些步骤
- idea设置识别.sql文件类型以及其他文件类型
- DataTable使用Linq进行分组汇总,将Linq结果集转化为DataTable
- 8大软件供应链攻击事件概述
- 读者让我总结一波 redis 面试题,现在肝出来了
猜你喜欢
word 公式编辑器 键入技巧 | 写数学作业必备速查表
腾讯136道高级岗面试题:多线程+算法+Redis+JVM
数的划分之动态规划
附加:对于“与数据表对应的实体类“,【面对MongoDB时,使用的@Id等注解】和【以前面对MySQL时,使用的@Id等注解】,是不同的;
[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection
px、em、rem的区别
4.3 基于注解的声明式事务和基于XML的声明式事务
Typora 使用保姆级教程 | 看这一篇就够了 | 历史版本已被禁用
The symbol table
Dynamic programming of the division of numbers
随机推荐
4.2 声明式事务概念
读者让我总结一波 redis 面试题,现在肝出来了
canal实现mysql数据同步
12、分页插件
8大软件供应链攻击事件概述
C语言 -- 操作符详解
想低成本保障软件安全?5大安全任务值得考虑
Resolved error: npm WARN config global `--global`, `--local` are deprecated
OpenGL绘制圆
信息学奥赛一本通 1312:【例3.4】昆虫繁殖
5个开源组件管理小技巧
C专家编程 第5章 对链接的思考 5.4 警惕Interpositioning
C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.5 Other Differences Between Arrays and Pointers
Landing, the IFC, GFC, FFC concept, layout rules, forming method, use is analysed
深度学习环境配置
string类简介
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.2 Why does my code not work
Tactile intelligent sharing - SSD20X realizes upgrade display progress bar
如何将 DevSecOps 引入企业?
使用Patroni回调脚本绑定VIP的坑