当前位置:网站首页>字符类型转换
字符类型转换
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
边栏推荐
猜你喜欢
随机推荐
Do students in the science class really understand the future career planning?
数据库操作 Day 6
Day 1
Time complexity and space complexity
365 day challenge leetcode1000 question - distance between bus stops on day 038 + time-based key value storage + array closest to the target value after transforming the array and + maximum value at t
[C language series] - print prime numbers between 100 and 200
Side effects and sequence points
rem与px与em异同点
The function of using wechat applet to scan code to log in to the PC web of the system
Database operation day 6
[event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises
Solution: find the position of the first and last element in a sorted array (personal notes)
适创科技以云仿真平台,支持“中国智造”升级
Basic use of redis
Day 1
Clickhouse learning (VIII) materialized view
Alibaba cloud Zhang Xintao: heterogeneous computing provides surging power for the digital economy
Pyqt5: Chapter 1, Section 1: creating a user interface using QT components - Introduction
Redirection and files
【无标题】









