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 }; }
相关文章推荐
- js判断undefined类型
- 使用FastJSON,将对象或数组和JSON串互转
- js面向对象编程,原型继承1
- js面向对象学习(转)
- js将json字符串转换为json
- js面向对象编程的继承问题
- C# 基础,JOject JArray构造json对象
- C# 基础,JOject JArray构造json对象
- javascript中的异常处理
- js传真实地址 C:\fakepath
- 使用Carthage管理SwfitJSON整合中遇到的问题
- JavaScript全局变量与局部变量实验
- js one() 方法
- Extjs 组件继承 模板说明(同GridPanel案件)
- jsp的内置对象
- Js实现MD5加密
- 解析没有key的Json
- Javascript 数组对象 操作
- javascript延时调用函数
- js 页面高度随浏览器变化