首页 > 其他分享 >js策略模式 以及 es6中 ?? 的用法

js策略模式 以及 es6中 ?? 的用法

时间:2023-03-23 14:37:20浏览次数:38  
标签:status es6 const map js 用法 null

策略模式,es6中 ?? 的用法

const judge = function(status){
	const map = [
		0: '普通用户',
		1: '管理员',
		2: '超级管理员'
	]
				
	return map[status]??'未知用户'
}

?? 是ES6提供的一个操作符,被称为非空运算符,例如 a?? ' b '  ,如果a的值不为null,则取a的值,如果a的值为null,则取b

标签:status,es6,const,map,js,用法,null
From: https://www.cnblogs.com/weiqian/p/17247323.html

相关文章