您的位置:首页 > Web前端 > JavaScript

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: