Javascript类型
2014-03-06 16:51
316 查看
var y = x.toString(2);
转换2进制
var y = (257).toString(0x10);
转换16进制
var a = true;
if(a == 1){
alert('aaa');
}
可以alert 。
(In fact, JavaScriptdoes just this and converts true and false to 1 and 0 when necessary.)
var point = { x:2.3, y:-1.2 };Object声明
An important featureof JavaScript is that functions are values that can be manipulated byJavaScript code. In many languages, including Java, functions are only asyntactic feature of the language --
they can be defined and invoked, but theyare not data types. The fact that functions are true values in JavaScript givesa lot of flexibility to the language. It means that functions can be stored invariables, arrays, and objects, and it means that functions
can be passed asarguments to other functions. This can quite often be useful. We'll learn moreabout defining and invoking functions, and also about using them as data values
function是一个数据类型。
This comparison istrue either if the my.prop property does not exist or if it does exist butcontains the value null. Since both null and the undefined value indicate anabsence of value, this equality
is often what we want. However, if you trulymust distinguish between a null value and an undefined value, use the ===identity operator or the typeof operator
Undefined和Null之间比较用==会返回true
var len = s.length;
In this case, sremains a string; the original string value itself is not changed. A newtransient String object is created, which allows us to access the lengthproperty, and then the transient object is discarded, with no change to theoriginal value s. If
you think this scheme sounds elegant and bizarrely complexat the same time, you are right. Typically, however, JavaScript implementationsperform this internal conversion very efficiently, and it is not something youshould worry about.
自动创建一个对象,调用方法后自动discard
var s = "helloworld"; // A primitivestring value
var S = newString("Hello World"); // AString object
转换2进制
var y = (257).toString(0x10);
转换16进制
var a = true;
if(a == 1){
alert('aaa');
}
可以alert 。
(In fact, JavaScriptdoes just this and converts true and false to 1 and 0 when necessary.)
var point = { x:2.3, y:-1.2 };Object声明
An important featureof JavaScript is that functions are values that can be manipulated byJavaScript code. In many languages, including Java, functions are only asyntactic feature of the language --
they can be defined and invoked, but theyare not data types. The fact that functions are true values in JavaScript givesa lot of flexibility to the language. It means that functions can be stored invariables, arrays, and objects, and it means that functions
can be passed asarguments to other functions. This can quite often be useful. We'll learn moreabout defining and invoking functions, and also about using them as data values
function是一个数据类型。
This comparison istrue either if the my.prop property does not exist or if it does exist butcontains the value null. Since both null and the undefined value indicate anabsence of value, this equality
is often what we want. However, if you trulymust distinguish between a null value and an undefined value, use the ===identity operator or the typeof operator
Undefined和Null之间比较用==会返回true
var len = s.length;
In this case, sremains a string; the original string value itself is not changed. A newtransient String object is created, which allows us to access the lengthproperty, and then the transient object is discarded, with no change to theoriginal value s. If
you think this scheme sounds elegant and bizarrely complexat the same time, you are right. Typically, however, JavaScript implementationsperform this internal conversion very efficiently, and it is not something youshould worry about.
自动创建一个对象,调用方法后自动discard
var s = "helloworld"; // A primitivestring value
var S = newString("Hello World"); // AString object
相关文章推荐
- javascript中关于类型判断的一些疑惑小结
- JavaScript基础知识之数据类型
- javascript 数据类型和值(基础版)
- javascript 判断是否为数组或对象或各种其它数据类型
- JavaScript之引用类型
- JavaScript中 ES6 generator数据类型详解
- JavaScript的类型检测
- JavaScript类型转换方法及需要注意的问题小结(挺全面)
- JavaScript 数据类型
- JavaScript高级程序设计第五章引用类型——RegExp类型
- JavaScript高级教程5.6之基本包装类型(详细)
- Javascript中常用类型的格式化方法小结
- 深入JavaScript类型判定
- JavaScript中的隐式类型转换
- Javascript基础系列之(三)数据类型 (数值 Number)
- JavaScript 的类型
- JavaScript之Dom节点类型、遍历节点数。
- javascript入门·脚本执行的时间的四种类型(赠送一个转换的小例题)
- ArcGIS api for javascript——图层-创建WMS图层类型的图层
- Javascript delete 引用类型对象