JavaScript 中原始資料型別與非原始資料型別之間的區別?
原始資料型別有數字、字串、布林值、浮點數,等等。非原始資料型別(引用型別)有陣列、物件等。
示例
var number=10; var stringValue="John"; var booleanValue=true; var obj={}; var newArray=new Array(); console.log("The data type is="+typeof number); console.log("The data type is="+typeof stringValue); console.log("The data type is="+typeof booleanValue); console.log("The data type is="+typeof obj); console.log("The data type is="+typeof newArray);
要執行上述程式,你需要使用以下命令 −
node fileName.js.
輸出
此處,我的檔名是 demo162.js。它將產生以下輸出 −
PS C:\Users\Amit\JavaScript-code> node demo162.js The data type is=number The data type is=string The data type is=boolean The data type is=object The data type is=object
此處為廣告