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. Data Flow ->> Pivot

    这个组件和SQL Server的Pivot基本就是一回事.不过我观察到SSIS的Pivot只支持SUM这种聚合类型,并没有找到哪个选择可以设置聚合类型,而T-SQL语法的Pivot则支持多种聚合类型, ...

  2. 【python爬虫】根据查询词爬取网站返回结果

    最近在做语义方面的问题,需要反义词.就在网上找反义词大全之类的,但是大多不全,没有我想要的.然后就找相关的网站,发现了http://fanyici.xpcha.com/5f7x868lizu.html ...

  3. Myeclipse2014配置JSF环境

    首先创建一个普通的webproject,然后看官网教程喽 https://www.genuitec.com/products/myeclipse/learning-center/web/myeclip ...

  4. R语言学习笔记——Base Graphics

    做exploratory data annalysis的作业,差点被虐死了,R从头开始,边做边学,最后搞到一点多才弄完,还有一个图怎么画都不对,最后发现是数据读取的时候有问题. 用来画图的数据来自:h ...

  5. poj-2376 Cleaning Shifts (排序+贪心)

    http://poj.org/problem?id=2376 john有n头牛做打扫工作,他想在t时间内每个时间都至少有一头牛在做打扫工作,第一头牛在1,最后一头牛在t时间,每一头牛工作都有一个开始时 ...

  6. python下载图片

    import re import  urllib.request   def getHtml(url): page = urllib.request.urlopen(url) html = page. ...

  7. Volley HTTP库系列教程(3)自定义RequestQueue和编写单例RequestQueue示例

    Setting Up a RequestQueue Previous  Next This lesson teaches you to Set Up a Network and Cache Use a ...

  8. HTML 空格的表示符号 nbsp / ensp / emsp 的区别?

      半角的不断行的空白格(推荐使用)   半角的空格   全角的空格   半角的不断行的空白格(推荐使用)    半角的空格     全角的空格

  9. leetcode Database2 (四)

    一.Duplicate Emails Write a SQL query to find all duplicate emails in a table named Person. +----+--- ...

  10. 如何为Eclipse安装Eclipse Marketplace插件

    Eclipse Marketplace是个插件应用商店,很实用的一个功能. 打开 eclipse,help--Eclipse Marketplace Client就能找到 有的eclipse中没有这个 ...