JS Data Type

JavaScript Data Types

JavaScript has dynamic types, the same variable can be used as different types. JS有动态变量类型。
var x;               // Now x is undefined
var x = 5;           // Now x is a Number
var x = "John";      // Now x is a String

JavaScript Strings

字符串(text)用单引号或双引号围住。
You can use quotes inside a string, as long as they don't match the quotes surrounding the string
在字符串中可以嵌套使用单引号、双引号
var answer="It's alright";
var answer="He is called 'Johnny'";
var answer='He is called "Johnny"';
Or you can put quotes inside a string by using the \ 使用斜杠屏蔽冲突引号
var answer='It\'s alright';
You can access each character in a string with its position (index) 通过下标选取字符串中某个字符
var carname="Volvo XC60";
var character=carname[7];

JavaScript Numbers

JavaScript has only one type of numbers. Numbers can be written with, or without decimals

JS只有一种数字类型,数字可以带小数,也可以没有小数点后面的部分。
Extra large or extra small numbers can be written with scientific (exponential) notation
超大或超小的数字可以用科学指数法表示。
var y=123e5;      // 12300000
var z=123e-5;     // 0.00123

JavaScript Arrays

Array indexes are zero-based, which means the first item is [0]
JS数组是以下标0开始的

JavaScript Objects

An object is delimited by curly braces. Inside the braces the object's properties are defined asname and value pairs (name : value) separated by commas。

JS对象由一对大括号定界的。对象的成员是由一对名字和值组成,由逗号分隔。

var person={firstname:"John", lastname:"Doe", id:5566};
Spaces and line breaks are not important 空格和分行不重要,因此也可以写为:
var person={
firstname : "John",
lastname  : "Doe",
id        :  5566
};

Accessing Object Properties

 两种方式引用对象的属性;

name=person.lastname;
name=person["lastname"];

Objects are just data, with added properties and methods. JS对象只是添加了属性和方法的数据

Properties are values associated with objects. Methods are actions objects can perform.


Declaring Variables as Objects

When a variable is declared with the keyword "new", the variable is declared as an object 

使用关键字new来声明变量是一个对象,JS中任何变量都可以是对象

var name = new String;
var x =    new Number;
var y =    new Boolean;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值