Data Types

5 Data Types

string, number, boolean, object, function

3 Object Types

object, array, date

2 Other Types

null, undefined

Type Conversion

Number/Boolean/Date -> String

String(x)  // x can be any number, expression or variable

x.toString()

String/Boolean -> Number

Number(x)

Number(' ') => 0

Number('') => 0

Number('1  2') => NaN  Number('1+2') => NaN

Number(false) => 0  Number(true) => 1

Operator '+'

+ can convert a variable to a number

+ '5' => 5

+ 'a' => NaN

Implicit Type Conversion

+ can also be applied in the cancatening the strings.

Infinity+(-Infinity) => NaN

+0+(+0) => +0, (-0)+(-0) => -0, (+0)+(-0) => +0

var c = a+b

if a is string:

  if b is string: return the concatenation of a+b   // 'x' + 'y' => 'xy'

  if b is not string : return a+b.toString

if a is number:

  if b is string: return a.toString+b   // 100+'23' => '10023'   '3' + 4 + 5  =>  '345'  3 + 4 + '5' => '75'

== will perform implict conversion on the varibale before comparing

string == number => Number(string) == number

boolean == ? => Number(boolean) == ?

object == ?(not obj) => valueof(object) == ?

null == undefined => return true

NaN == ? => return false // NaN == NaN => return false *NaN is unequal to every value including itself

object1 == object2 => compare if they point to the same object

Similiar with  <,  >,  <=,  >=

&& and ||

null && ? => null  NaN && ? => NaN // if theie is a null/NaN/undefined evaulted value, return null/NaN/undefined

null && NaN => null  NaN && null => NaN  undefined && null => undefined

same as the cases in '||'

a && b

if a evalutes to be true: return b (original value before evalution)

else: return a (original value before evalution)

a || b

if a evalutes to be false: return b (original value before evalution)

else: return a (original value before evalution)

name = other_name || 'default'

JavaScript Type Conversion的更多相关文章

  1. error: expected constructor, destructor, or type conversion before '.' token

    今天写代码是遇到这样一个问题error: expected constructor, destructor, or type conversion before '.' token:立马网上查,原来是 ...

  2. 【错误】expected constructor, destructor, or type conversion before '.' token - 第八个游侠的日志 - 网易博客

    [错误]expected constructor, destructor, or type conversion before '.' token - 第八个游侠的日志 - 网易博客 [错误]expe ...

  3. Type Conversion

    文章著作权归作者所有.转载请联系作者,并在文中注明出处,给出原文链接. 本文原更新于作者的github博客,这里给出链接. 什么是转换 转换是接受一个类型的值并使用它作为另一个类型的等价值的过程.转换 ...

  4. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion(一)

    题外话:本篇是对之前那篇的重排版.并拆分成两篇,免得没了看的兴趣. 前言 在Spring Framework官方文档中,这三者是放到一起讲的,但没有解释为什么放到一起.大概是默认了读者都是有相关经验的 ...

  5. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion(二)

    接前一篇 Spring Framework 官方文档学习(四)之Validation.Data Binding.Type Conversion(一) 本篇主要内容:Spring Type Conver ...

  6. delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决

    delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决,需要打这个 ...

  7. java 反射 报错:Attempt to get java.lang.Integer field "..." with illegal data type conversion to int

    类: Integer id; 反射时: Field f = User.class.getDeclaredField("id"); f.setAccessible(true); in ...

  8. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion

    本篇太乱,请移步: Spring Framework 官方文档学习(四)之Validation.Data Binding.Type Conversion(一) 写了删删了写,反复几次,对自己的描述很不 ...

  9. [C++] Type Conversion(类型转换)

    Type Conversion(类型转换) Two kinds of type conversion explict type conversion(显式类型转换) impict type conve ...

随机推荐

  1. Android 如何处理崩溃的异常

    Android中处理崩溃异常    大家都知道,现在安装Android系统的手机版本和设备千差万别,在模拟器上运行良好的程序安装到某款手机上说不定就出现崩溃的现象,开发者个人不可能购买所有设备逐个调试 ...

  2. Win API 内存整理

    记得我的笔记本上曾经安装了一款名为内存整理大师的软件,当时觉得挺好用而且挺NB的,就是导致开机启动有点慢. 当时我就在想,内存整理是怎么实现的?不过那是水平实在是不怎么样,估计连windows程序的消 ...

  3. View页面根据权限显示不同的内容

    1.View中根据权限显示相关操作按钮 @if (CoreTools.CheckAction(HttpContext.Current, "Delete"))        {    ...

  4. git使用ssh协议,生成公钥和私钥,并指定私钥

    http://superuser.com/questions/232373/how-to-tell-git-which-private-key-to-use In ~/.ssh/config, add ...

  5. 第六讲(二) Hibernate HQL查询

    HQL查询:Criteria查询对查询条件进行了面向对象封装,符合编程人员的思维方式,不过HQL(Hibernate Query Lanaguage)查询提供了更加丰富的和灵活的查询特性,因此Hibe ...

  6. C#配置系统未能初始化

    如果配置文件中包含 configSections 元素,则 configSections 元素必须是 configuration 元素的第一个子元素.",将appSettings放到conf ...

  7. poj 2479 (DP)

    求一个区间内连续两段不相交区间最大和. // File Name: 2479.cpp // Author: Missa_Chen // Created Time: 2013年06月22日 星期六 16 ...

  8. boost编译批处理脚本

    ------------buildboost.bat-------------- @REM Used to build boost lib.@REM by Rock Wang @transoft 20 ...

  9. struts2自定义声明校验器

    1 //新建一个validators.xml在src根资源下,会覆盖default.xml的validators,所以你懂得 //接着,若使用声明式校验,则要把配置文件xxxAction-valida ...

  10. ecshop 用户名和邮箱都能登陆

    1.打开/includes/modules/integrates/integrate.php文件,并找到下面代码 if ($this->check_user($username, $passwo ...