javascript - Why does console.log exclude my zero from logging?
问题描述
class Person {
constructor(name, address, phone) {
this.name = name;
this.address = address;
this.phone = phone;
}
call() {
console.log(`Calling ${this.phone}...`)
}
}
const tom = new Person('Tom', 'Uden', 0619616);
tom.call();
When calling this, the console only shows "619616". When I add console.log(tom.phone)
it does log the entire number. Why is the zero excluded when calling a method?
解决方案
您将其用作整数。
如果要保留零,请将其用作字符串。
class Person {
constructor(name, address, phone) {
this.name = name;
this.address = address;
this.phone = phone;
}
call() {
console.log(`Calling ${this.phone}...`)
}
}
const tom = new Person('Tom', 'Uden', '0619616');
tom.call();
如需解释,请查看评论或此链接
另一个值得阅读的参考:https : //stackoverflow.com/a/37004175/10473393(感谢@Amy 分享评论)
推荐阅读
- javascript - 如何让浏览器检测输入字段值的变化?
- ios - 自定义 tabview 标题栏
- wordpress - 重力形式:在元框中打印条目信息(不只是默认布局显示)
- alibaba-cloud - Harbor 向阿里巴巴 ACR 推送镜像失败
- javascript - 如何在下拉选择中获取数字值并从所选值创建元素输入文本框?
- javascript - 正则表达式:仅在后跟任何字符时替换空格否则修剪
- python - 日志记录级别是信息,但只显示警告。Python 日志记录
- amazon-web-services - 在 Ubuntu 上构建 docker 映像:来自守护进程的错误响应:无效的过滤器“参考”
- html - 如何使容器在特定点向左偏移并填充css中的剩余空间
- d3.js - D3 v6如何正确加入?