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