js基本数据类型介绍

基本数据类型有7种:number、string、boolean、null、undefined、symbol、bigint

//typeof 关键字,可以判断数据类型

number 数字

不带引号的数字,包括负数、小数等都是数字类型

const age = 18;
console.log(typeof age); // number

string 字符串

两边有单引号或者双引号的字符

const str = 'hello';
console.log(typeof str); // string

boolean 布尔型

布尔值只有两个,true、false

true表示是,false表示否,通常用来做判断

const flag = true;
console.log(typeof flag); // boolean

null 空

// 空值会被typeof判断为object
let obj = null;
console.log(typeof obj); // object

undefined 未赋值

字面意思,例如一个变量未赋值,那么他的数据类型就是undefined

// 未赋值的变量默认值是undefined,类型也是undefined
let num;
console.log(typeof num); // undefined

symbol

symbol 表示一个独一无二的值

let num = Symbol(); // 使用Symbol()方法定义一个symbol
console.log(typeof num); // symbol

bigint

表示大于2^53 - 1整数,可以用来表示任意大的整数

const num = 10n;    // 在整数后面加n来定义一个bigint
console.log(typeof num); // bigint

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值