1 Star 0 Fork 0

math.most/js_study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
005转换为bool.js 565 Bytes
一键复制 编辑 原始数据 按行查看 历史
Administrator 提交于 2021-05-05 12:23 +08:00 . 运算符
// 使用Boolean函数
// 数字转bool, 除了0和NaN, 其余都为true
const a = '123';
const b = Boolean(a);
console.log('b: ', b, typeof b); // b: true boolean
// 字符串转bool, 除了'', 其余都为true
const c = '';
const d = Boolean(c);
console.log('d: ', d, typeof d); // d: false boolean
// null和undefined转bool, 都为false
const e = null;
const f = Boolean(e);
console.log('f: ', f, typeof f); // f: false boolean
const g = undefined;
const h = Boolean(g);
console.log('h: ', h, typeof h); // h: false boolean
// 对象也会转换为true
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mathmost/js_study.git
git@gitee.com:mathmost/js_study.git
mathmost
js_study
js_study
master

搜索帮助