js基礎知識

2021-09-12 16:34:14 字數 594 閱讀 3343

1、js有哪些資料型別?

基礎資料型別有:boolean,string,number,undefined,null

引用資料型別:object(array,date,regexp,function)

2、如何判斷乙個陣列的型別。

如果用typeof array,其資料型別是 object。

方法1 用乙個陣列的方法,對於不是陣列的物件,會返回undefined。

如:

let arr = ;

let obj = {};

console.log(arr.slice);

console.log(obj.slice);

列印:[function: slice]

undefined

方法二: instanceof運算子 用來判斷乙個建構函式的prototype屬性所指向的物件是否存在另外乙個要檢測物件的原型鏈上

let arr = [1,2,3];

let obj = {};

console.log(arr instanceof array);

console.log(obj instanceof object);

JS基礎知識

本週抽空學習了一些js新手需要知道的知識 1 js中用 來賦值,例如var a 1.2 迴圈結構和c 基本相同。3 簡單 基本 資料型別 number string boolean undefined null。4 複雜 引用 資料型別 object array date function。還有一些...

js基礎知識

1.ecmascript 直譯器 0,1 幾乎沒有相容性問題 2.dom 文件,物件,模型 document object model 相容性一般 3.bom 瀏覽器 物件,模型 browser object model 完全不相容 number string boolean function ob...

js基礎知識

1.型別和型別轉換 1 值型別 string 字串 number 數值 boolean 布林值 undefined null 2 引用型別 array 陣列 object 物件 function 函式 2.null 和 undefined 1 undefined表示未定義。對於沒有初始化的變數 函式...