当前位置:网站首页>字符类型转换
字符类型转换
2022-07-29 05:10:00 【Try your best】
一.其他类型转换成字符串
// var a=10;
1.通过运算
// a=a+"";//10+"" a="10"
2.强制转换
// var a=10;
// //String(a)把对象值a转换成字符串
// console.log( String(a));//"10"
二.其他类型转换成数字
//var a="10.56";
//
## 1.通过运算
//a=a-0;
// a=a*1;
// a=a/1
// console.log(a);
2.通过Number():可以将不同的值转换成数字
// a=Number(a)
// console.log(a);//number
3.通过一元运算符+ -
// a=+a;
4.通过parseInt(),parseFloat()方法进行转换
// a=parseInt(a);//10
//console.log(a);//10
//var a="10.56";
// a=parseFloat(a)//10.56
//console.log(a)//10.56
三.字符串转换成布尔值
var a="";
// console.log(!a);//true
// console.log(!!a);//false
var a="1"
// console.log(!a);//false
// console.log(!!a);//true
四.查看字符类型
var a=15;
console.log(typeof a);//number
var a="15";
console.log(typeof a);//string
var a=false;
console.log(typeof a);//boolean
var a=null;
console.log(typeof a);//object
var a=undefined;
console.log(typeof a);//undefined
边栏推荐
- Cryengine Technology
- On Paradigm
- ClickHouse学习(一)ClickHouse?
- Terminal shell common commands
- 力扣994:腐烂的橘子(BFS)
- eggjs 创建应用知识点
- 365 day challenge leetcode 1000 questions - day 041 two point search completion anniversary + nth magic number + online election
- With cloud simulation platform, Shichuang technology supports the upgrading of "China smart manufacturing"
- ClickHouse学习(六)语法优化
- Day 3
猜你喜欢

【C语言系列】— 不创造第三个变量,实现两个数的交换

Day 3

365 day challenge leetcode 1000 questions - day 039 full binary tree inserter + find peak II + snapshot array

虚拟增强与现实第二篇 (我是一只火鸟)

ClickHouse学习(四)SQL操作

VIM editor use
![[C language series] - realize the exchange of two numbers without creating the third variable](/img/7c/468000bcbf740c9dd3535f2734728a.png)
[C language series] - realize the exchange of two numbers without creating the third variable

Alibaba cloud Zhang Xintao: heterogeneous computing provides surging power for the digital economy

【C语言系列】— 打印100~200之间的素数

PyQt5:第一章第1节:使用Qt组件创建一个用户界面-介绍
随机推荐
Allocate memory: malloc() and free()
Common shortcut keys for Ad
365 day challenge leetcode 1000 questions - day 039 full binary tree inserter + find peak II + snapshot array
浅谈范式
适创科技以云仿真平台,支持“中国智造”升级
365 day challenge leetcode 1000 questions - day 041 two point search completion anniversary + nth magic number + online election
【C语言系列】—深度解剖数据在内存中的存储(二)-浮点型
js深拷贝-笔记
力扣994:腐烂的橘子(BFS)
shell基本操作(下)
Talking about Servlet
Best practices for elastic computing in the game industry
ANSI C type qualifier
冒泡排序 C语言
Occt learning 003 - MFC single document project
One dimensional array exercise
【C语言系列】— 不创造第三个变量,实现两个数的交换
About local variables
ClickHouse学习(三)表引擎
Cryengine3 debugging shader method