Has 5 primitive types: Undefined, Null, Boolean, String, Number.

typeof  operator

Undefined return undefined

Null return object

Boolean return boolean

String return string

Number return number

Null returns object, this is an error in the original JS. Today, null is considered a placeholder for an object,  even though, it is a primitive types.

The Undefined Type

Use typeof with Object undefined, it also give "undefined", like the variables defined but not initialized.

The Null Type

alert(null == undefined);  //outputs "true"

Even though this is equal, they have different meanings.

The Boolean Type

true false

The Number Type

Number can present 32-bit integer and 64-bit floating point value.

Define floating-point value, you should use like: var fNum = 5.0; This will stored as string, and converted to number until calculation.

e-notion:  var fNum = 3.125e7, fNum2=3.125e-7;

Number.MAX_VALUE  Number.MIN_VALUE

>Number.MAX_VALUE  ->   Number.POSITIVE_INFINITY

<Number.MIN_VALUE   ->   Number.NEGATIVE_INFINITY

Function isFinite(value) returns Boolean

NaN: When convert from other type and failed, the number value is NaN, can't calculate.

alert(NaN == NaN);  //outputs "false"

Function isNaN(value) returns Boolean

The String Type

''

""

Conversions

Converting to a string

Booleans, numbers, strings are pseudo-objects.

All objects, include   pseudo-objects, all have toString().

Boolean:   true  false

Number:

var num = 10;

alert(num.toString());   //10

alert(num.toString(2)); // 1010

alert(num.toString(16)); // A

Converting to a number

parseInt():  validate the character in position 0 and determines if this is a valid number, if it isn't , return NaN, else continue untile a character isn't a valid number, and parse the part of valid.

var iNum1 = parseInt("123blue"); //returns 123

var iNum1 = parseInt("22.5"); //returns 22, decimal point is not valid

var iNum2 = parseInt("10", 2) ;//returns 2

var iNum3 = parseInt("0XA");//returns 10

var iNum4 = parseInt("010");//returns 8

var iNum5 = parseInt("010", 10);//returns 10

parseFloat(): if have more than one decimal point, all are invalid except the first one. No radix mode.

var iNum1 = parseFloat("12.34.56"); //returns 12.34

var iNum2 = parseInt("123blue"); //returns 123.0

var iNum3 = parseInt("010");//returns 10

var iNum4 = parseInt("0XA");//returns NaN

Type Casting

Boolean(value)

String with at least one character, a number other than 0, or an object: return true;

Empty string, the number 0, undefined or null, return false.

Number(value)

Works similar to parseInt() & parseFloat(), except that it converts the entire value.

String(value)

Like toString(), but can produce a string for a null or undefined value without error.

var s1 = String(null);   //"null"

var oNull = null;

var s2 = oNull.toString();  //won't work

Reference Types

ECMAScript doesn't have classes in the traditional sense. ECMAScript defines "object definitions" that are logically equivalent to classes in other programming languages.

The Object class

Like the java.lang.Object in java.

Properties

constructor

prototype

Methods

hasOwnProperty(property)

isPrototypeof(object)

toString()

valueOf()

The Boolean Class

var oFalseObject = new Boolean(false);

Var bResult = oFalseObject  && true;    //outputs true

Because all objects converted to true.

The Number class

toFixed(), toFixed(n): returns a string representation of a number with a specified number of decimal points.      0 <= n <= 20

toExponential(n): returns a string with the number formatted in e-notation.

toPrecision():

var oNumberObject = new Number(99);

alert(oNumberObject .toPrecision(1));  //outputs "1e+2"

alert(oNumberObject .toPrecision(2));  //outputs "99"

alert(oNumberObject .toPrecision(3));  //outputs "99.0"

The String class

The String class has length property.

charAt(): returns a string containing the character in that position.

charCodeAt():

Chapter 2 JavaScript Basic的更多相关文章

  1. 《JavaScript高级程序设计》chapter 1: javascript 简介

    1.2.2 文档对象模型     DHTML的出现让开发人员无需重新加载页面就可以修改其外观了. 1.2.3 浏览器对象模型(BOM)     BOM真正与众不同的地方在于他作为javascript实 ...

  2. Javascript Basic Operation Extraction

    1.  logic operation : '&&' and '||'  .For this two logic operations,its' results are inconcl ...

  3. JavaScript Basic

    Exercise-1 Write a JavaScript program to display the current day and time in the following format. T ...

  4. JavaScript Basic Memo

    1.this 的指向 1).由 new 调用?绑定到新创建的对象. 2). 由 call 或者 apply(或者 bind)调用?绑定到指定的对象. 3). 由上下文对象调用?绑定到那个上下文对象. ...

  5. JavaScript- The Good Parts CHAPTER 2

    I know it well:I read it in the grammar long ago.—William Shakespeare, The Tragedy(悲剧:灾难:惨案) of Titu ...

  6. Javascript DOM编程艺术

    Chapter 0 为什么读这本书?作为js入门书,补基础,由于本书代码demo较简单,并没有贴代码,只记录一些自己要注意的知识点以及代码脚本 Chapter 1: javascript简史 DOM全 ...

  7. 良好的JavaScript编码风格(语法规则)

    编码风格 1.概述 "编程风格"(programming style)指的是编写代码的样式规则.不同的程序员,往往有不同的编程风格. 有人说,编译器的规范叫做"语法规则& ...

  8. Javascript 高级程序设计--总结【四】

    *******************************  Chapter 11 DOM扩展  ******************************* 主要的扩展是 选择符API 和 H ...

  9. JavaScript 的基本语法

    说明:此类博客来自以下链接,对原内容做了标注重点知识,此处仅供自己学习参考! 来源:https://wangdoc.com/javascript/basic/introduction.html 1. ...

随机推荐

  1. django 模板实现换行

    django中的模板并不能实现自动换行,遇到/n的话不会自动换行,毕竟/n是python里面的换行符,html怎么可能认识呢? 那如何实现在模板中换行呢 <p> {{ article.co ...

  2. UML分析设计顺序

    1.用例图:最简单的模型,与设计无关 2.活动图:类似流程图 3.用例图:对1的细化,分解后的Actor及Use Case 4.用例图:分解后的Actor及抽取的数据实体 5.类图:数据结构图 6.顺 ...

  3. Appium处理滑动方法是swipe

    滑动API:Swipe(int start x,int start y,int end x,int y,duration) 解释: int start x-开始滑动的x坐标:int start y - ...

  4. block的知识点

    // //  main.m //  1211块练习 // //  Created by jerehedu on 14/12/11. //  Copyright (c) 2014年 jereh. All ...

  5. UITableView Scroll to top 手动设置tableview 滚动到 顶部

    UITableView Scroll to top 手动设置tableview 滚动到 顶部 [mainTableView scrollRectToVisible:CGRectMake(0,0,1,1 ...

  6. [Android] SQLite数据库之增删改查基础操作

        在编程中常常会遇到数据库的操作,而Android系统内置了SQLite,它是一款轻型数据库,遵守事务ACID的关系型数据库管理系统,它占用的资源非常低,可以支持Windows/Linux/Un ...

  7. 机器学习系列(8)_读《Nature》论文,看AlphaGo养成

    作者:viewmode=contents">龙心尘 && viewmode=contents">寒小阳 时间:2016年3月. 出处:http://bl ...

  8. C#创建COM组件供VB,PB,Delphi调用

    1  COM组件概述 COM是微软公司为了计算机工业的软件生产更加符合人类的行为方式开发的一种新的软件开发技术.在COM构架下,人们可以开发出各种各样的功能专一的组件,然后将它们按照需要组合起来,构成 ...

  9. 解决在IE9,IE10浏览器下,程序没有任何错误,easy ui页面不加载任何数据的问题

    对于web应用程序,经常用到开发人员工具,按F12,可以调试脚本,可以查看监视网络,查看各页面加载时间,非常方便,今天在调试js时,不小心打开了兼容性视图, 之后每次打打开页面时,均不显示页面post ...

  10. oc 阿拉伯数字转中文数字

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; formatter.numberStyle = NSNumberFor ...