标签:radix 特殊 function 小数点 小数 define 目标 class 比较
var a = 1;
//conloe.log(typeof(a)) 值为Number
var a = [];
//conloe.log(typeof(a)) 值为Object
var a = {};
//conloe.log(typeof(a)) 值为Object
var a = null;
//conloe.log(typeof(a)) 值为Object
var a = true;
//conloe.log(typeof(a)) 值为Boolean
var d;
//conloe.log(typeof(b)) 值为Undefined
var a = function(){};
//conloe.log(typeof(a)) 值为function
console.log("1" + 1) //11
console.log("1" + "1") //11
console.log("1" * 1) //1
console.log("1" -1) //0
console.log("2" + 1) //21
console.log("2"- 1) //1
var demo = '123'
demo = Number(demo) //把demo装换为数字
console.log(typeof(demo)) //number
var demoB = true
console.log(Number(demoB)) //1 boolean值转为数字类型以后1为真, 0为假
console.log(Number("sfjafja")) //NaN 不能转为为数字的值转换为数字后, 值为NaN
var demoN = null
console.log(Number(demoN)) //值为0
var demoun = undefined
console.log(Number(demoun)) //NaN
var i = '123'
console.log(parseInt(i), typeof(parseInt(i))) //123 number
var i = "123.9"
console.log(parseInt(i), typeof(parseInt(i))) //123 number
var demoi = false
console.log(parseInt(demoi), typeof(parseInt(demoi))) //NaN number
var demor = 3
console.log(parseInt(demor, 2)) // NaN , 默认把3当成2进制的数,由于2进制中不存在3, 所以输出为NaN
var demorx = 'b'
console.log(parseInt(demorx, 16)) //11 ,把b当成16进制数,然后把它转换为10进制数
var demos = '100px'
console.log(parseInt(demos)) //100 parseInt会从开头的数字开始看,看完不是数字为值
var demols = "afaf100fafa"
console.log(parseInt(demols)) // NaN
console.log(parseFloat("100")) //100 整数的时候parseFloat是不会添加.0 de
console.log(parseFloat("100.1")) //100.1
console.log(parseFloat('100.0.01')) //100 默认只会取一个小数点
console.log(parseFloat('100.12raga')) //100.12
var demostr = String(function (){
console.log('I an String')
})
console.log(demostr) //function (){ console.log('I an String')}
var demot = 1213
var demots = toString(demot)
var demounde = toString(undefined)
console.log(typeof (demounde)) //string
console.log(typeof(demots)) //string
console.log(typeof(demot.toString()))
var demo = 123
console.log(demo.toString(8), typeof demo.toString(8)) //173 string
隐式数据类型的转换是在一定条件下,触发了JavaScript内部的转换机制,内部调用的是显示的数据类型转换
隐式数据类型的触发条件主要情况: isNaN(), +/-/*//, ++, --, >,>=,=<,> < ,%, !, &&, ||, ==, !=
console.log(isNaN('123')) //false
console.log(isNaN('abc')) //true
console.log(isNaN(null)) //false Number(null) 是0 所以其值为false
console.log(isNaN(undefined)) //true
var abc = + "abc"
console.log(typeof (abc), abc) //number NaN
var abc = "abc" + 1
console.log(typeof (abc), abc) //string abc1 当加号两侧有一个是字符串的时候就调用String()方法把它转换成String
console.log(typeof ("1" * 1), 1 * "1") // numeber 1
console.log(typeof (1 / "1"), 1 / 1) //number 1
console.log(typeof (2 % "10"), 2 % "10") //numberi 2
console.log(1>= "2") //会转换成number型在进行比较
console.log("1">"2") //会直接比ascall码值
console.log(3 > true) //true
console.log(1 == true) //true
console.log(false == 1) //false
console.log(Number(null)) //0
console.log(null == 0)
console.log(Number(null) == 0) //true
console.log(1 == "1") //true
console.log(1 ==="1") //false
console.log(1 === true) //false
console.log(1 != "1") //false
console.log(1 !== "1") //true
标签:radix 特殊 function 小数点 小数 define 目标 class 比较
原文地址:https://www.cnblogs.com/ghostdot/p/11372466.html