Bảng sau đây tóm tắt các giá trị trả về có thể có của
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8. Để biết thêm thông tin về các loại và nguyên hàm, hãy xem thêm trang cấu trúc dữ liệu JavaScriptTypeResultUndefined_______02Null// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
3 [lý do]Boolean// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
4Number// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
5BigInt// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
6String// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
7Symbol// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8Function [triển khai [[Call]] theo thuật ngữ ECMA-262; các lớp cũng là các hàm]// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
9Bất kỳ đối tượng nào khác// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
3Danh sách các giá trị này là đầy đủ. Không có công cụ tuân thủ thông số kỹ thuật nào được báo cáo để tạo ra [hoặc đã từng sản xuất] các giá trị khác với các giá trị được liệt kê. Internet Explorer cũ là trình duyệt duy nhất được biết là triển khai các giá trị trả về bổ sung, trước khi thông số kỹ thuật loại bỏ hành vi của
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8 trả về các chuỗi do triển khai xác định cho các đối tượng kỳ lạ không theo tiêu chuẩn không thể gọi đượcví dụ
sử dụng cơ bản
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
loại null
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
0Trong lần triển khai JavaScript đầu tiên, các giá trị JavaScript được biểu diễn dưới dạng thẻ loại và giá trị. Thẻ loại cho các đối tượng là
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
02. // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
03 được biểu diễn dưới dạng con trỏ NULL [// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
04 trong hầu hết các nền tảng]. Do đó, // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
03 có // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
02 làm thẻ loại, do đó giá trị trả về của // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8 là // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
3. [thẩm quyền giải quyết]Một bản sửa lỗi đã được đề xuất cho ECMAScript [thông qua tùy chọn tham gia], nhưng đã bị từ chối. Nó sẽ dẫn đến
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
09Sử dụng toán tử mới
Tất cả các hàm xây dựng được gọi với
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
80 sẽ trả về các giá trị không nguyên thủy [// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
3 hoặc // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
9]. Hầu hết các đối tượng trả về, với ngoại lệ đáng chú ý là // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
83, trả về một hàm// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8Cần dấu ngoặc đơn trong cú pháp
Toán tử
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8 có độ ưu tiên cao hơn toán tử nhị phân như phép cộng [// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
85]. Do đó, dấu ngoặc đơn là cần thiết để đánh giá loại kết quả cộng// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
4Tương tác với các biến chưa được khai báo và chưa được khởi tạo
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8 thường luôn được đảm bảo trả về một chuỗi cho bất kỳ toán hạng nào mà nó được cung cấp. Ngay cả với số nhận dạng không được khai báo, // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8 sẽ trả về // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
2 thay vì đưa ra lỗi// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
6Tuy nhiên, sử dụng
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8 trên các khai báo từ vựng [// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
40 // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
41 và // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
42] trong cùng một khối trước dòng khai báo sẽ tạo ra một // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
43. Các biến trong phạm vi khối nằm trong vùng chết tạm thời từ khi bắt đầu khối cho đến khi quá trình khởi tạo được xử lý, trong thời gian đó, nó sẽ báo lỗi nếu được truy cập// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
1Hành vi đặc biệt của tài liệu. tất cả các
Tất cả các trình duyệt hiện tại hiển thị một đối tượng máy chủ không chuẩn
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
44 với loại // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
45// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
4Mặc dù
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
44 cũng là giả và tương đương với // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
45, nhưng nó không phải là // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
45. Trường hợp của // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
44 có kiểu // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
2 được phân loại trong tiêu chuẩn web là "cố ý vi phạm" tiêu chuẩn ECMAScript ban đầu về khả năng tương thích webPhương thức tùy chỉnh có loại cụ thể hơn
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8 rất hữu ích, nhưng nó không linh hoạt như yêu cầu. Ví dụ: // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
62 là // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
3, cũng như // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
64, // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
65, v.v.Để có tính cụ thể hơn trong việc kiểm tra các loại, ở đây chúng tôi trình bày một hàm
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
66 tùy chỉnh, phần lớn bắt chước hành vi của // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
8, nhưng đối với các loại không nguyên thủy [i. e. đối tượng và hàm], nó trả về một tên loại chi tiết hơn nếu có thể// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
5Để kiểm tra các biến có khả năng không tồn tại mà nếu không sẽ tạo ra một
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
43, hãy sử dụng // Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // Despite being "Not-A-Number"
typeof Number["1"] === "number"; // Number tries to parse things into numbers
typeof Number["shoe"] === "number"; // including values that cannot be type coerced to a number
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // note that a number within a string is still typeof string
typeof typeof 1 === "string"; // typeof always returns a string
typeof String[1] === "string"; // String converts anything into a string, safer than toString
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean[1] === "boolean"; // Boolean[] will convert values based on if they're truthy or falsy
typeof !!1 === "boolean"; // two calls of the ! [logical NOT] operator are equivalent to Boolean[]
// Symbols
typeof Symbol[] === "symbol";
typeof Symbol["foo"] === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === "object";
typeof new Date[] === "object";
typeof /regex/ === "object";
// The following are confusing, dangerous, and wasteful. Avoid them.
typeof new Boolean[true] === "object";
typeof new Number[1] === "object";
typeof new String["abc"] === "object";
// Functions
typeof function [] {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
69 vì không thể bắt chước hành vi này bằng mã tùy chỉnh