当前位置:网站首页>JS cast and implicit type conversion and Unicode encoding
JS cast and implicit type conversion and Unicode encoding
2022-06-09 21:35:00 【qq_ forty-six million three hundred and two thousand two hundre】
Cast
One 、 Other data types Cast to String
Method 1: toString() Method
let a = 123
a =a.toString()
console.log(a,typeof(a),'111'); //123 string 111

let b = null
b = b.toString()
console.log(b,typeof(b),'222'); //TypeError: Cannot read properties of null (reading 'toString')
let c = undefined
c = c.toString()
console.log(c,typeof(c),'222'); //TypeError: Cannot read properties of undefined (reading 'toString')
* Method 2:String() function *
let a = 123
a = String(a)
console.log(a,typeof(a),'111'); // 123 string 111
String() The function can also put null and undefined To string type ;
let b = null
b = String(b)
console.log(b,typeof(b),'222'); // null string 222
let c = undefined
c = String(c)
console.log(c,typeof(c),'333'); // undefined string 333
Two 、 Other data types Cast to Number
Method 1:Number() function 

let name = ''
name = Number(name)
console.log(name,typeof(name)); //0 'number'
let sex = ' '
sex = Number(sex)
console.log(sex,typeof(sex)); //0 'number'
let a = "123"
a = Number(a)
console.log(a,typeof(a)); //123 'number'
let b = "123a"
b = Number(b)
console.log(b,typeof(b)) //NaN 'number'
let c = null
c = Number(c)
console.log(c,typeof(c)); //0 'number'
let d = undefined
d = Number(d)
console.log(d,typeof(d)); //NaN 'number'
Method 2:parseInt() 、parseFloat()
let a = "123dfsl"
a = parseInt(a)
console.log(a,typeof(a)); //123 'number'
let b = "b123"
b = parseInt(b)
console.log(b,typeof(b)); //NaN 'number'
let c = "123.365ab"
c = parseInt(c)
console.log(c,typeof(c)); //123 'number'
let d = "123.365ab"
d = parseFloat(d)
console.log(d,typeof(d)); //123.365 'number'

let a = true
a= parseInt(a)
console.log(a,typeof(a)); //NaN 'number'
3、 ... and 、 Other data types Cast to Boolean
Implicit type conversion
Logical operators !、&&、||
!( Not )
Non operation will first put a To boolean type ,“hello” Of boolean The type is true, !a by false,!!a by true; therefore !!a Yes, it will a To its boolean value ;
&& ( And )

&&( And ) It's looking for false, If the first value is false, The second value will not be executed
||( or )

||( or ) It's looking for true, If the first value is true, The second value will not be executed .

let a = 3 && 0
console.log(a); // 0
let a = NaN && 2
console.log(a); //NaN
let b = 'hellow' || ''
console.log(b); // hellow
Unicode code

边栏推荐
- Fedformer:frequency enhanced decomposedtransformer for long term series forecasting[still learning...]
- 739. 每日温度 - 力扣(单调递减栈)
- How to make our self built site have a custom domain name (1)
- PaddleNLP--UIE(二)--小样本快速提升性能(含doccona标注)
- Numpy duplicate data
- Gbase8s database select Clause 6
- Huawei announced the establishment of three corps and two system departments, and has established 20 Corps in total
- Mmdetection train your own coco data set and common problems
- [cf] 797 div3 E. Price Maximization
- Sequence traversal of binary tree
猜你喜欢

逻辑回归总结

如何定比特到服務器CPU飆高的原因
![Paddlenlp general information extraction technology UIE [i] industrial application examples: information extraction {entity relationship extraction, Chinese word segmentation, accurate entity markers,](/img/96/1356766947b138a6e5647ddfe7e9a7.png)
Paddlenlp general information extraction technology UIE [i] industrial application examples: information extraction {entity relationship extraction, Chinese word segmentation, accurate entity markers,

mmdetection训练自己的COCO数据集及常见问题

Set up ngrok server, realize intranet penetration service, and realize online access from external network to internal network
![【流量分析】buu_[安洵杯 2019]Attack](/img/6a/e8bd90e931ef8dfdca1cd9c66f0695.png)
【流量分析】buu_[安洵杯 2019]Attack
![[flow analysis] Buu_ [an Xun cup 2019]attack](/img/6a/e8bd90e931ef8dfdca1cd9c66f0695.png)
[flow analysis] Buu_ [an Xun cup 2019]attack

03 Wireshark TCP

Mysql:1062 Duplicate entry '1' for key 'PRIMARY'

Sort - quick sort
随机推荐
10 common high-frequency business scenarios that trigger IO bottlenecks
二叉搜索树
PaddleNLP通用信息抽取技术UIE【一】产业应用实例:信息抽取{实体关系抽取、中文分词、精准实体标。情感分析等}、文本纠错、问答系统、闲聊机器人、定制训练
线性回归总结
[flow analysis] Buu_ [an Xun cup 2019]attack
idea:new没有class
Make money by doing sideline work. These popular we media platforms have made a lot of profits
Thread interrupt
Gbase8s database select Clause 3
Pychart always displays the collecting data solution after entering the debug mode
Goldfish rhca memoirs: do447 management list -- management list variables
Idea:new no class
[cf] 797 div3 E. Price Maximization
Latex mathematical symbols Encyclopedia
Understand go modules' go Mod and go sum
兰吉尔FFC3 电表电能量采集终端替代方案(DLMS红外光电采集器)
区间值(单调栈)
go安装图文教程
unbutu配置DHCP服务器及客户端连接
QT database application 21 data grouping export