There are two ways to correctly type checks number:

console.log(typeof 99.66); // number
console.log(Object.prototype.toString.call(99) === '[object Number]'); // true

When using Number.prototype methods, some of them return String as result:

console.log((99.12345678).toPrecision(5)); // 99.123

We can see this string:

console.log(typeof (99.12345678).toPrecision(5)); // string

If we want to conver this string type of number:

console.log(parseFloat((99.12345678).toPrecision(5))); // 99.123

Last in Chrome dev tool, you can see that, Number is shown in Blue color, and string is shown in Black color:

console.log(parseFloat((99.12345678).toPrecision(5)));
console.log((99.12345678).toPrecision(5));

[Javascript] Correctly Type-Checking Numbers的更多相关文章

  1. Refused to execute script from '....js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.md

    目录 问题描述 解决过程 总结 问题描述 在整合 Spring Boot.Spring Security.Thymeleaf 的练习中,对页面进行调试时,发现如下错误提示: Refused to ex ...

  2. 类型检查和鸭子类型 Duck typing in computer programming is an application of the duck test 鸭子测试 鸭子类型 指示编译器将类的类型检查安排在运行时而不是编译时 type checking can be specified to occur at run time rather than compile time.

    Go所提供的面向对象功能十分简洁,但却兼具了类型检查和鸭子类型两者的有点,这是何等优秀的设计啊! Duck typing in computer programming is an applicati ...

  3. 类型检查 Type Checking 一些编程语言并不安全 类型化语言的优点 定型环境 (符号表) 断言的种类

    Compiler http://staff.ustc.edu.cn/~bjhua/courses/compiler/2014/ http://staff.ustc.edu.cn/~bjhua/cour ...

  4. <script language = "javascript">, <script type = "text/javascript">和<script language = "application/javascript">(转)

          application/javascript是服务器端处理js文件的mime类型,text/javascript是浏览器处理js的mime类型,后者兼容性更好(虽然application/ ...

  5. Check类之duplicate declaration checking/Class name generation/Type Checking

    1.duplicate declaration checking /** Check that variable does not hide variable with same name in * ...

  6. Dynamic type checking and runtime type information

    动态类型的关键是将动态对象与实际类型信息绑定. See also: Dynamic programming language and Interpreted language Dynamic type ...

  7. JavaScript Number Type Checker

    JavaScript Number Type Checker Number.isInteger // static 方法 Number.isInteger(value) https://develop ...

  8. JavaScript input type=file 获取文件大小及类型限制

    <input name="txtName" type="file" id="pic" onchange="loadImage ...

  9. JavaScript的type属性等于text/html 例子

    在使用JavaScript标签<script>的时候,其中type最常用的就是text/javascript 其实这个type还有其他用法,下面直接给出例子: type属性为text/ht ...

随机推荐

  1. JAVA日常之四

    构造函数 又称“构建器”,函数名称与类名称完全相同,无返回值. 每个类都有构造函数. 可以自定义构造函数,并且可以创建多个重载/过载的构造函数. 若没有手动创建该函数,总会存在一个默认的构造函数(无参 ...

  2. 请写一段 PHP 代码 ,确保多个进程同时写入同一个文件成功

    方案一: function writeData($filepath, $data) { $fp = fopen($filepath,'a'); do{ usleep(100); }while (!fl ...

  3. shell习题第12题:批量创建用户

    [题目要求] 用shell脚本实现如下需求 添加user_00 -- user_09 10个用户,并且给他们设置一个随机密码,密码要求10位包含大小写字母及数字,注意要把每个用户的密码记录到一个日志文 ...

  4. 监控 Kubernetes 集群应用

    Prometheus的数据指标是通过一个公开的 HTTP(S) 数据接口获取到的,我们不需要单独安装监控的 agent,只需要暴露一个 metrics 接口,Prometheus 就会定期去拉取数据: ...

  5. Springboot使用外置tomcat的同时使用websocket通信遇到的坑

    随意门:https://blog.csdn.net/qq_43323720/article/details/99660430 另外,使用了nginx的话,需要注意开放websocket支持 serve ...

  6. 测试工作小工具~总结&下载连接

    1.Gif录制小工具(动图提单 ≖ᴗ≖) 地址:https://licecap.en.softonic.com/download

  7. VMware与主机联网设置

    1.编辑-虚拟机网络编辑器 2.虚拟机设置 3. 4.主机ping虚拟机

  8. excel 导入

    public static DataTable ExcelToDataTable(string fileName, string sheetName, bool isFirstRowColumn) { ...

  9. VBA精彩代码分享-3

    在开发VBA程序中,我们可能会需要用代码处理VBA工程,包括启用VBA工程访问,启用所有宏,动态插入代码,动态删除代码,动态添加引用和自动创建模块等等,本次的分享内容便以这些为主. 启用VBA工程访问 ...

  10. 关于Mybatis的几件小事(一)

    一.Mybatis简介 1.Mybatis简介 MyBatis是支持定制化SQL.存储过程以及高级映射的优秀的持久层框架. MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集. M ...