关键字与变量的区别

变量名:自己根据规则给变量起的一个名字。

关键字:关键字用于执行特定操作的一类字符。按照规则,关键字也是语言保留的,不能用做标识符。

比如 if else 这些 就是关键字

abstract

enum

int

short

boolean

export

interface

static

byte

extends

long

super

char

final

native

synchronized

class

float

package

throws

const

goto

private

transient

debugger

implements

protected

volatile

double

import

public

 

 

undefined 和 null  是否是 关键字?

答案: undefined严格意义来说不是关键字,是属于变量。 null 是属于关键字的。

// let null = '111';
// console.log(null)   //Uncaught SyntaxError: Unexpected token null 未捕获的SyntaxError:意外的令牌null
// Unexpected token 表示语法错误 所以是关键字

// console.log(if)     //Uncaught SyntaxError: Unexpected token if
// if是关键字 显示的错误和 null 是一样。

// let undefined = '111';
// console.log(undefined)  //Uncaught SyntaxError: Identifier 'undefined' has already been declared 未捕获的SyntaxError:标识符“undefined”已经声明
// 表示是已经声明过不能重复声明

// const a = 1;
// const a =2;
// console.log(a)  //Uncaught SyntaxError: Identifier 'a' has already been declared
// 是一个错误代表 undefined为变量

这两个网站有给我提示:

https://www.cnblogs.com/qdjl/p/9241947.html?tdsourcetag=s_pcqq_aiomsg

https://blog.csdn.net/nanruitao10/article/details/50878198

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值