Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js 类型

作者:寂寞算什么   发布日期:2026-01-20   浏览:101

// JavaScript 类型示例

// 1. 基本类型 (Primitive Types)
let num = 42; // 数字类型 (Number)
let str = "Hello, World!"; // 字符串类型 (String)
let bool = true; // 布尔类型 (Boolean)
let n = null; // Null 类型
let u = undefined; // Undefined 类型
let sym = Symbol("symbol"); // Symbol 类型

// 2. 引用类型 (Reference Types)
let obj = { name: "Alice" }; // 对象类型 (Object)
let arr = [1, 2, 3]; // 数组类型 (Array), 数组也是对象的一种
let func = function() { console.log("This is a function"); }; // 函数类型 (Function), 函数也是对象的一种

// 3. 检查类型的方法
console.log(typeof num); // "number"
console.log(typeof str); // "string"
console.log(typeof bool); // "boolean"
console.log(typeof n); // "object" (这是一个历史遗留问题,null 被认为是对象)
console.log(typeof u); // "undefined"
console.log(typeof sym); // "symbol"
console.log(typeof obj); // "object"
console.log(typeof arr); // "object" (数组也是对象)
console.log(typeof func); // "function"

// 使用 instanceof 检查引用类型
console.log(arr instanceof Array); // true
console.log(func instanceof Function); // true

这段代码展示了 JavaScript 中的基本类型和引用类型的定义及其检查方法。

上一篇:js closest

下一篇:js 或者

大家都在看

js 数组对象排序

js 对象数组排序

js 数组删掉第一个值

js fill

js 数组连接

js json数组

js 数组复制

js 复制数组

js 数组拷贝

js 数组对象合并

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站