value=undefined
var name辕狰;
在申請(qǐng)變量的時(shí)候勋眯,如name浪箭,其值實(shí)際是undefined穗椅;
alert(document.getElementById("num"));
當(dāng)獲取一個(gè)不存在的對(duì)象的時(shí)候,如num奶栖,會(huì)返回null匹表;
javaScript數(shù)據(jù)類型
String(字符串),Boolean(布爾值),Number(數(shù)字),Array(數(shù)組),Object(對(duì)象),
Null(空),undefined(未定義)
字符串的表達(dá)形式
源碼
var carname1="Volvo XC60";
var carname2='Volvo XC60';
var answer1='It\'s alright';
var answer2="He is called \"Johnny\"";
var answer3='He is called "Johnny"';
顯示:
Volvo XC60
Volvo XC60
It's alright
He is called "Johnny"
He is called "Johnny"
數(shù)組
創(chuàng)建數(shù)組的方式:
方式一:
var num=new Array();
num[0]="1";
方式二:
var num=new Array("1","2","ads");
方式三:
var num=["1","2","ads"];
對(duì)象
對(duì)象由花括號(hào)分隔。在括號(hào)內(nèi)部宣鄙,對(duì)象的屬性以名稱和值對(duì)的形式(name:value)來定義袍镀。屬性由逗號(hào)分隔;
var person={firstname:"John", lastname:"Doe", id:5566};
調(diào)用對(duì)象屬性的兩種方式:如:person對(duì)象
方式一:
person.lastname;
方式二:
person["lastname"];
常見的創(chuàng)建對(duì)象的方式:
方式一:
var demo1=Demo(); //創(chuàng)建一個(gè)方法冻晤;
function Demo()
{
var object=new Object();
object.age=12;
object.name="liu";
object.firstF=function()
{
}
}
document.write(demo1.age); //調(diào)用對(duì)象的屬性苇羡;
方式二:
var demo2=new Demo(); //創(chuàng)建一個(gè)對(duì)象類;
function Demo()
{
this.name="小名";
this.age=12;
this.firstF=function()
{
}
}
document.write(demo2.age); //調(diào)用對(duì)象的屬性明也;
疑惑:js中var num=new Array()和var num=new Array有什么區(qū)別: