当前位置:网站首页>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
边栏推荐
- 离线采集怎么看sql执行计划
- leetcode 12. 整数转罗马数字
- 【JS】js给对象动态添加、设置、删除属性名和属性值
- C专家编程 第5章 对链接的思考 5.1 函数库、链接和载入
- 如何打造一篇优秀的简历
- About yolo7 and gpu
- C Expert Programming Chapter 5 Thinking about Linking 5.3 5 Special Secrets of Library Linking
- Resolved error: npm WARN config global `--global`, `--local` are deprecated
- Delphi-C端有趣的菜单操作界面设计
- Write golang simple C2 remote control based on gRPC
猜你喜欢
MySQL日志篇,MySQL日志之binlog日志,binlog日志详解
读者让我总结一波 redis 面试题,现在肝出来了
自动化测试的成本高效果差,那么自动化测试的意义在哪呢?
Tactile intelligent sharing - SSD20X realizes upgrade display progress bar
某母婴小程序加密参数解密
There is an 8 hour difference between the docker installation of mysql and the host.
嵌入式系统驱动初级【3】——字符设备驱动基础中_IO模型
在被面试官说了无数次后,终于潜下心来整理了一下JVM的类加载器
使用Loadrunner进行性能测试
深度学习21天——准备(环境配置)
随机推荐
想低成本保障软件安全?5大安全任务值得考虑
嵌入式系统驱动初级【4】——字符设备驱动基础下_并发控制
4.2 声明式事务概念
获取单选框选中内容
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.2 Why does my code not work
C1认证之web基础知识及习题——我的学习笔记
应届生软件测试薪资大概多少?
力扣:96.不同的二叉搜索树
使用Patroni回调脚本绑定VIP的坑
Chapter 5 C programming expert thinking 5.4 alert Interpositioning of links
[SemiDrive source code analysis] [MailBox inter-core communication] 47 - Analysis of RPMSG_IPCC_RPC mode limit size of single transmission and limit bandwidth test
System design. How to design a spike system (full version transfer)
Use Patroni callback script to bind VIP pit
static在不同位置定义变量居然还有不同的含义?
LCP 17. 速算机器人
C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.3 What is a Declaration and What is a Definition
某母婴小程序加密参数解密
[C language advanced] program environment and preprocessing
Uni-app 小程序 App 的广告变现之路:全屏视频广告
MySQL日志篇,MySQL日志之binlog日志,binlog日志详解