javascript基础(1):

语法

ECMAscript语法大量借鉴了C类语言的语法:

标识符:指变量、函数、属性的名字,或者函数的参数。

标识符命名规则:第一个字符必须是字母、下划线或$符号,其他字符可以使字母、下划线、数字和$符号。

注释: //单行           /*多行注释*/

严格模式:Javascript在更严格的条件下运行

常用关键字:break do instanceof typeof case else new var return void continue for switch while function this                default if delete in try

保留关键字:没有在ECMAscript中用到,但是将来可能会用作关键字。int long class public const等等

变量:var temp也可以不写var,但是不推荐使用(容易造成全局污染)。

基本数据类型:undefined null number string boolean

复杂数据类型:Object Array Date RegExp Function

判断数据类型:  typeof  something

判断是否属于那种类型: something instanceof  Type

注意:在number类型中NAN是非数值,isNAN(something)返回值true为非数字,false为”可以转化为数字的变量“。

var temp = 1;
alert(typeof temp);//弹出number
-------------------------------------
var temp;
alert(typeof temp);//弹出undefined
-------------------------------------
alert(something);//弹出undefined报错了,没有声明
-------------------------------------
var temp="asdfgh";
alert(typeof temp);//弹出string
-------------------------------------
var temp=ture;
alert(typeof temp);//弹出boolean
-------------------------------------
var temp =null;
alert(typeof temp);//弹出null


你可能感兴趣的:(JavaScript,基本数据类型)