JS 資料型別入門與typeof操作符

2022-07-12 09:06:09 字數 1112 閱讀 7541

標準的資料型別劃分:

基本型別:

number(數字)、string(字串)、undefined、boolean(布林值)、null(空物件)

//空物件與非空物件,最大的區別就是不能進行屬性操作

物件型別(復合型別):

object (物件)

物件型別中並沒有函式,函式不屬於資料;

typeof操作符:

是用來檢測變數的資料型別,對於值或變數使用

typeof

操作符會返回如下字串。**如下

var nub = 10 ;

console.log(typeof nub); // number 數字

/* 從負無窮到正無窮的數字,以及nan(not a number)

*/var str = "asdsadsad"; // string 字串

console.log(typeof str);

/* 任何包含在引號中的一串字元 都屬於字串

*/var is = true; // boolean 布林值

console.log(typeof is);

/* true 和 false

*/var arr = ; //object 物件

console.log(typeof arr);

console.log(null == arr);//注意空陣列不等於空物件

var obj = null; //object 物件

console.log(typeof obj);

var el = document; //object 物件

console.log(typeof el);

/* 物件:陣列、null、元素物件、object

*/var u; //undefined 未定義

console.log(typeof u);

var fn = function()

console.log(typeof fn);

function fn2()

console.log(typeof fn2);

在typeof中資料型別分為:

typeof 與 js資料型別

js的資料型別有null undefied string number boolean object六個,然後我之前的 誤區 typeof的返回值和js的資料型別是一樣的。然而並不是 t.t 1.typeof方法返回值的是 字串 string number function object boole...

使用typeof檢測資料型別

我們一般使用typeof檢測資料型別 typeof x 與typeof x 的作用是一樣的,返回結果是檢測到的資料型別 number 檢測的值是數值 boolean 檢測的值是布林型的,true或false string 檢測的值是字串 object 檢測的值是物件,陣列或null function...

JS資料型別與型別轉換

1.資料型別 5個基本資料型別 number string boolean undefined null 和乙個引用型別 object 2.判斷型別 typeof 7種 number string boolean undefined object function symbol 3.型別轉換 1 強...