您的位置:首页 > Web前端 > JavaScript

JavaScript的基本概念

2015-07-08 18:27 716 查看
/*
* 区分大小写
* */

//使用严格模式
function doSomeThing(){
"use strict"//加上这句会告诉编译器  启动严格模式
//......
}

/*
* 数据类型
* Undefined     未初始化或未定义的变量 唯一的值就是undefined
* Null          一个空的引用
* Boolean       true/false   注意其他数据类型与Boolean数据类型的转化
* Number        数值类型        不要去比较浮点型数据的大小 Infinity(-Infinity)->超过数值范围 NaN->应该返回数值而未返回数值
*               数值转换 Number() parseInt()  parseFloat()
* String        字符串类型  转化  .toString()
* Object        对象类型 就是键值对
*               object类型具有的方法
*                   Constructor 创建当前对象的函数
*                   hasOwnProperty(propertyName)    是否具有某个属性
*                   isPropertyOf(object)        是否是另一个对象的原型
*                   propertyIsEnumberable(propertyName) 能够使用for-in
*                   toLocaleString()
*                   toString()
*                   valueOf()
* 可以使用 typeof 操作符,获取变量的类型
*
*
* Undefined派生自Null 所以 alert( null == undefined) ->true
*
* */
function testVarType(){
var a;
document.write(typeof a);//undefined
document.write("<br/>");
document.write(typeof b);//undefined
document.write("<br/>");

var c = null;
document.write(typeof c);//object
document.write("<br/>");

document.write(typeof false);//number
document.write("<br/>");

document.write(typeof "123");//string
document.write("<br/>");

var d = {"1":1};
document.write(typeof d);//object
document.write("<br/>");

var e = doSomeThing;
document.write(typeof e);//function
document.write("<br/>");

document.write(null == undefined);//true
document.write("<br/>");

document.write("MAX:"+Number.MAX_VALUE);
document.write("<br/>");
document.write("MIN:"+Number.MIN_VALUE);
document.write("<br/>");

document.write(isNaN("123"));//false
document.write("<br/>");
document.write(isNaN("xixi"));//true 无法转化为数字
document.write("<br/>");
document.write(isNaN(123));//false
document.write("<br/>");
document.write(isNaN(d));//如果是对象 先valueof 不行在 toString
document.write("<br/>");
}


/**
* Created by sherry on 15-7-7.
*/
/*
* 创建Object的两种方式
* */
function createObject(){
var person = new Object();
person.name = "zln";
person.age = 26;

//通过字面量定义的对象不会调用Object构造函数
var personNew = {
name:"zln",
age:26
};
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: