JavaScript - 知识点总结

本文深入探讨了JavaScript中变量的类型识别、基本数据类型的转换、字符串与数值间的操作,以及特殊值NaN的理解,同时提供了关于JavaScript数据类型的实用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. js中变量为若类型,typeof 可以确定一个变量的数据类型

--undefined  值未定义

--boolean   布尔

--string   字符串

--number  数值

--object   对象或者null

--function  函数

eg: var b = (typeof  19.0 == "number");   typeof b;    //boolean   and  b = true;


2. toString() 方法

--无论数字是什么类型,toString()默认都是按照十进制来输出

--基模式:带一个进制参数

eg: document.write((8).toString(2));    //1000


3. parseInt() 方法:第一个参数是要解析的字符串,第二个可选,默认十进制

eg:   parseInt("1000", 2);   //8


4. +运算符

2 + 3;  //5

"2" + "3" ;  //23

"2" + 3;  //23

1 + 2 + "3";  //33


5. NaN

var nan = NaN;

nan === NaN ;  //false

isNaN(nan);   //true


6. 字符串String

var s = new String("hello);

s = s + "world";  //hello world;

s[4];  //o;

typeof s;  //object

typeof "hello";  //string

var s1 = new String("hello");

var s2 = new String("hello");

s1 === s2;  //false;

s1 == s2;  //false;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值