js系列-基本类型和引用类型typeof和instanceof

解析 typeof 和 instanceof 阅读详情

#最新的 ECMAScript 标准定义了 8 种数据类型:

#类型检测:typeof

    let num = 123;
    console.log(typeof num);//'number'
    let str = 'abc';
    console.log(typeof str);//'string'
    let boo = true;
    console.log(typeof boo);//'boolean'
    let un;
    console.log(typeof un);//'undefined'
    let fun = function () { };
    console.log(typeof fun);//'function'
    let nul = null;
    console.log(typeof nul);//'object'
    let arr = [];
    console.log(typeof arr);//'object'
    let obj = {};
    console.log(typeof obj);//'object'

上面使用typeof类型检测,不能区分数组和对象,我们可以使用 instanceof

    let arr = [];
    console.log(arr instanceof Array);//true
    let obj = {};
    console.log(obj instanceof Object);//true

instanceof:检测构造函数是否在对象的原型链上

#定义变量的两种方式

    //字面量
    let str = 'abc';
    console.log(str);//'abc'
    //对象方式
    let strob = new String('abc');
    console.log(strob);//String('abc')

嵌入式SPI总线抽象设计:跨平台驱动与分层解耦实践 SPI(串行外设接口)是嵌入式系统中应用最广泛的同步串行通信协议,其核心价值在于高吞吐、低开销与硬件简洁性。其工作原理基于主从架构、全双工/半双工时序及片选(CS)控制,依赖CPOL/CPHA组合定义四种标准模式。在工程实践中,SPI常面临硬件资源受限、多外设共用总线、MCU平台迁移等挑战,导致驱动复用率低、维护成本高。通过结构体+函数指针实现的分层抽象——将物理总线、协议适配与设备驱动解耦,可显著提升代码可移植性与扩展性。该方法天然支持硬件SPI与GPIO模拟SPI双模式切换,并已在STM32等主流MCU 阅读详情

相关推荐

数字IC设计技能篇之如何在RTL级降低功耗?

以上就是本次降低芯片功耗的部分心得和收获,由于是在芯片设计阶段还没办法后端直接给出power的报告,前端一般使用spyglass和fsdb来进行功耗分析,后续会更新如何使用spyglass在前仿阶段进行power的分析,以及持续更新有关RTL级降低功耗的相关内容。

mzynk的博客 1206

JS之instanceof详解

instanceof 用于检测构造函数的 prototype 属性是否出现在某个实例对象的原型链上。 语法:object instanceof constructor object:某个实例对象 constructor:某个构造函数 用来检测 constructor.prototype 是否存在于参数 object 的原型链上。 示例 // 定义构造函数 function C () {} function D () {} // 实例化一个 o 对象 var o = new C() // tru

wfly blog 12万+

vasp-自旋轨道耦合(SOC)计算步骤

在VASP中执行自旋轨道耦合(SOC)计算,具体的计算步骤如下: 结构优化获取CONTCAR文件 自洽计算(collinear normal VASP calculations)获取IBZKPT,CHGCAR和WAVECAR文件。 SCF+SOC计算,在此步骤中,将步骤2中的IBZKPT复制为KPOINTS,以便两个步骤具有相同的k网格,因此可以读取步骤2中的CHGCAR和WAVECAR文件。 能带结构计算,在此步骤中,将KPOINTS改为高对称点,读取步骤3中的CHGCAR和WAVECAR文件。

懒散的鱼与消失的猫 3万+

js中的instanceof原理

instanceof是用来检测构造函数的属性是否出现在某个实例对象的原型链上。但是也存在缺陷,就是它不能精确的判断 Object 类的具体数据类型。如何实现instanceof?

分享学习成果,希望可以帮助到你。 3689

别再到处找密钥了!手把手教你搞定Halcon 24.11/25.05的试用授权(附每月更新提醒)

本文详细介绍了Halcon 24.11/25.05试用授权的获取与配置方法,包括解密新版授权机制、快速配置指南、每月更新规律及多版本共存管理技巧。帮助开发者避免常见授权问题,提升工作效率,特别适合机器视觉领域的初学者和专业人士。

weixin_29238147的博客 1235

数字IC后端实战:OCC电路时钟树综合的5个关键技巧(附Synopsys工具配置)

本文深入探讨了数字IC后端设计中OCC电路时钟树综合的实战技巧。针对工具自动平衡导致的绕线拥塞和时序问题,文章提出了分段处理的核心思路,并详细阐述了通过物理隔离、分段长树策略以及Synopsys工具链(如ICC2、PrimeTime)的精准配置来优化function clk与occ clk路径的关键方法,旨在提升时序收敛性和可制造性。

jwt8token的博客 863

js的各种数据类型判断(typeof、instanceof、Object.prototype.toString.call()、constructor、in、hasOwnProperty)

1.typeof Object.prototype.toString.call() constructor in hasOwnProperty() 基础类型: String、Number、Boolean、null、undefined、Symbol 存储在栈中,赋值变量和比较均为数据本身。 引用类型:Object、Array、Map、Function 存储在堆中,使用new创建,赋值变量和比较均是内存地址。

muzidigbig的博客 1万+

【华为机试真题 Python实现】分苹果

《华为机试真题》专栏含牛客网华为专栏、华为面经试题、华为OD机试真题。如果您在准备华为的面试,期间有想了解的可以私信我,我会尽可能帮您解答,也可以给您一些建议!本文解法非最优解(即非性能最优)。A,B两个人把苹果分为两堆,A希望按照它的计算规则等分苹果,他的计算规则是按照二进制加法计算,并且不计算走位,12+5=9(1100+0101=9), B的计算规则是十进制加法,包括正常进位,B希望在满足A的情况下获取苹果重量最多,输入苹果的数量和每个苹果重量,输出满足A的情况下获取的苹果总重量, 如果无法满足A的要

3415

详解JS中的instanceof使用及手写instanceof

instanceof 是什么? instanceof 是用来判断左侧对象是否是右侧构造函数的实例化对象,或则说左侧对象能否通过其隐式原型 **[[proto]]**在原型链上一层层向上查找到右侧函数的原型对象,即函数原型对象出现在实例对象的原型链上就返回 true。 通俗的理解: 右侧是不是左侧的爸爸、爷爷、祖宗,只要左侧对象继承自右侧函数就为 true instanceof 使用方式: object instanceof 构造函数,左侧必须为对象类型,右侧必须为函数类型。手撕instanceof, 原理

qq_40868156的博客 1万+

数据服务:数据服务框架Magic-API 介绍及实践

接口快速开发框架 基于Java的接口快速开发框架,编写接口将通过magic-api提供的UI界面完成,自动映射为HTTP接口,无需定义Controller、Service、Dao、Mapper、XML、VO等Java对象即可完成常见的HTTP API接口开发 。在线页面快速开发平台 基于 vue 的在线页面快速开发平台,主要把所有的 vue 代码都改为在线配置,最终获得一个 json 格式的页面新一代爬虫平台 基于Java实现的新一代爬虫平台,以图形化方式定义爬虫流程,不写代码即可完成爬虫。今天给大家安利一

GIS摆渡人 2071

Centos7系统添加中文支持(附中文语言包)

这里以centos7.6为例,在安装系统是没有选择中文,之后如果需要添加中文支持。在命令行执行后,会提示启动图形模式失败,转为启动文本模式。文本模式其实和图形模式差不多,操作需要用键盘而不是鼠标。在弹窗后,通过上下键选择Chinese(P.R of China) - 中文(简体):然后,按Tab键选择Yes,点击回车。rebootlocale可以看到系统语言已经变成了zh_CN.utf-8:之后,服务器上的中文名称就可以正常显示正常了。

悦分享 689

JavaScript中的instanceof运算符

JavaScript中的原型,原型链和instanceof运算符详解。

weixin_43263355的博客 6608

2023年全国职业院校技能大赛 网络系统管理服务模块 Linux部分讲解

网络系统管理,Linux,服务部署,Chinaskills,2023国赛

weixin_62926639的博客 1551

rangechecks 检测代码检测到超出范围的数组访问。_夯实基础系列(一)数据类型及其检测及进阶...

1.系列介绍第一节,讲解数据类型,及其常规的检测方法,数据存储形式,垃圾回收,包括面试中常常要求的手写的一些方法。2.JS中数据类型JS数据类型分为两大类:基本类型和引用类型。基本类型包含:string, number. boolean, undefined, null, symbol六种;引用类型有:对象一种。面试官:“那么什么是基本类型什么是引用类型呢?”小明:“基本类型是简单的数据...

weixin_39675038的博客 790

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

JS中typeof和instanceof的用法小解

javascript中,测试数据类型用到typeof 和 instanceof. 1. typeof一般测试基本类型(Undefined、Null、Boolean、Number、String),对引用类型一律返回object(Function引用类型返回Function) 测试基本类型: var a="oo"; var b=true; var c=""; var d=nu

形而上的小鱼 7233

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

【JS】typeof和instanceof的区别是什么?

instanceof和typeof是两个运算符,常用来判断一个变量是否为空,或者是什么类型的。typeof返回值是一个字符串,该字符串说明运算数的类型。一般可以使用 typeof 来获取一个变量是否存在,对于 Array,Null 等特殊对象使用 typeof 一律返回 object。instanceof 用于判断一个变量是否某个对象的实例,如 var a=new Array();alert(a instanceof Array); 会返回 true.........

青春木鱼的博客 4500

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

typeof与instanceof区别

js是一个弱类型的语言,所以一般想知道当前变量是哪一种类型必须判断类型,都知道判断类型的两种方式:typeof、 instanceof 它们各有缺点:typeof适用于基础数据类型判断,引用类型判断都是object。 instanceof 针对实例对象是否属于该对象,但严重存在原型继承,所以判断最好在两个对象之间 typeof typeof 是一个一元运算,放在一个运算数之前,运算数可以是任意类型...

lulu_678的博客 4595

JavaScript 类型检查操作符typeof 和 instanceof 的区别详解

JavaScript类型检查方法对比:typeof和instanceof是两种常用的类型检查操作符,但存在显著差异。typeof适用于所有值,返回类型字符串,对原始值有效,但无法区分数组/null与普通对象;instanceof仅检查对象,验证原型链关系,能识别数组和继承关系,但对原始值无效且跨窗口可能失效。typeof适合检查变量定义和基本类型,instanceof适合对象类型验证。最佳实践建议根据场景组合使用:数组检查用Array.isArray(),null用===,自定义类用instanceof,同

weixin_43170787的博客 1025

javascript typeof 和 instanceof 的区别和联系

这篇文章是我看完《JavaScript高级程序设计(第2版)》书籍的随笔文章,目的只有一个,以备自己和网友们方便参考和记忆! typeof是什么?       typeof 是一个操作符,主要的目的是检测一个变量是不是基本数据类型的变量,同时也可以说是确定一个变量是字

raisezhang 的专栏 1万+

【JavaScript】深入js中的基本类型和引用类型(栈堆讲解)

js中的基本类型和引用类型 1.JavaScript中的变量类型有哪些? (1)基本类型(基本类型):字符串(string)、数值(number)、布尔值(boolean)、undefined、null (这5种基本数据类型是按值访问的,因为可以操作保存在变量中的实际的值)、symbol (ECMAScript 2016新增了一种基本数据类型 ) (2)引用类型:对象(Object)、数组(Ar...

Umbrella_Um的博客 1007

了解JavaScript中的基本类型值和引用类型值

/创建空对象并将其引用赋给变量avar b={};//创建空对象并将其引用赋给变量bvar c=[];//创建空数组并将其引用赋给变量c以上示例中,变量a和变量b都是指向了一个空对象,如果new Object()不传参数的话,那么用new Object()和{}来创建对象的效果是相同的。但是如果传入不同的参数,会有不同的效果。传入String 返回String,类似new String()传入Number 返回Number,类似new Number()

冰咖啡的专栏 1156

深入解析:JavaScript中typeof与instanceof的原理及区别

摘要:JavaScript中的typeof和instanceof是两种类型检测工具,但原理和用途不同。typeof通过类型标签快速判断基本数据类型(如"number"、"string"),但对引用类型(如数组、对象)统一返回"object",且存在typeof null === "object"的历史遗留问题。instanceof则通过原型链判断对象是否属于某个构造函数,适用于引用类型检测,但无法用于基本类型。两者各有优劣:ty

m0_46335150的博客 1096

typeof和instanceof的区别

1.typeof是什么? typeof 是一个操作符,主要的目的是检测一个变量是不是基本数据类型的变量,同时也可以说是确定一个变量是字符串,数值,布尔值,还是undefined 的最佳工具 示例代码 在这里插入var a=&quot;zhangqian&quot;; var b=true; var c=10; var d; var e=null; var f=new Object(); alert(typeof ...

qq_43288097的博客 5218

鸿蒙中,类型检查typeof 和 instanceof 操作符

摘要: 鸿蒙应用开发中,typeof和instanceof是类型检查的核心操作符,但适用场景不同。typeof用于检测基本数据类型(如"number"、"string"),但对对象仅返回"object";instanceof则验证对象是否为特定类的实例(如数组、自定义组件)。关键区别在于:typeof针对原始类型,instanceof适用于引用类型。鸿蒙开发中建议结合两者实现类型守卫,例如判断API返回数据或组件类型,同时注意typeof null

梦想不只是梦与想的博客 1511

JavaScript typeof和instanceof区别详解

开发过程中,我们经常要判断一个变量的类型,那你知道js中有多少方式判断变量类型呢? 1. typeof typeof 用于基本类型的判断,js有7中基本类型,他们分别是: string、number、boolean、undefined、null、symbol、bigint。 它们分别使用typeof 判断的结果是: typeof 'hello'; // string typeof 123; // number typeof true; // boolean typeof undefined;

代码君 1619

JS中typeof和instanceof的区别

区别: typeof运算符用来检测基本数据类型 使用方法:typeof opera或者typeof(operand) instanceof运算符用来检测对象类型(引用类型) 准确些可以说:来判断某个对象是否是某个类的一个实例 是则返回true,否则返回false 使用方法:variable instanceof constructor 1. 基本数据类型 typeof用来检测五种基本数据类型 s...

zmjのblog 244
上一篇: js系列-for循环for in,for of,forEach循环遍历
下一篇: js系列-string字符串,模板字面量
前端蜗牛君
博客等级 码龄10年 274粉丝 158原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值