3-1 資???簡?

JavaScript ƫA]Data Type^iTApUG

󤣦PƫAܼơAڭ̥i typeof() ƨӶǦ^ƫAAШUCdҡG

Example]typeof01.htm^G

dҪlɮצpUG

lɡ]typeof01.htm^G]ǦϰUYi^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>typeof() 藍PƫA^ǭ</h2>
<hr>

<script>
x = "This is a string";
document.write("rG" + typeof(x)+"<br>");
x = 100;
document.write("ƦrG" + typeof(x)+"<br>");
x = 10==10;
document.write("LG" + typeof(x)+"<br>");
function square(n){
	return(n*n);
}
document.write("ơG" + typeof(square)+"<br>");
x = new Date();
document.write("G" + typeof(x)+"<br>");
x = ["Mon", "Tue", "Wed"];
document.write("}CG" + typeof(x)+"<br>");
x = {"Mon":"Game", "Tue":"Sports", "Wed":"Karaoke"};
document.write("rG" + typeof(x)+"<br>");
student = new Object();
student.name = "Timmy";
student.age = "25";
student.phone = "575-1114";
document.write("ۭqG" + typeof(student)+"<br>");
</script>

<hr>
</body>
</html>

ЯSO`NG

JavaScript 򥻸ƫAβզXƫAA|bUCU`CHUN JavaScript SƫAA]t null undefinedC

uundefinedvO@دSƫAAMΨӧP_UCرpG

  1. sbܼơGŧiABwȪܼơC
  2. lƪܼơGwŧiAwȪܼơC
pUG ШUCdҡG

Example]undefined01.htm^G

dҪlɮצpUG

lɡ]undefined01.htm^G]ǦϰUYi^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
<title>undefined d</title>
</head>

<body>
<h2 align=center>undefined d</h2>
<hr>

<script>
// notDeclare ܼƥgLŧiAҥHL
//  typeof(notDeclared) |Ǧ^ "undefined" r
if (typeof(notDeclared) == "undefined")	
	document.write("notDeclared Qŧi<br>");
document.write("typeof(notDeclared)="+typeof(notDeclared)+"<br>");

// declare ܼƥugLŧiA|lơAȬO undefined]DrI^
//  typeof(declared) |Ǧ^ "undefined" r
var declared;
if (declared==undefined)		
	document.write("declared wŧiQҩl<br>");
document.write("declared="+declared+"<br>");
document.write("typeof(declared)="+typeof(declared)+"<br>");
</script>

<hr>
</body>
</html>

unullvOt@دSƫAAU@ӽdҡAiΨˬd null UةʽMΪkG

Example]null01.htm^G

dҪlɮצpUG

lɡ]null01.htm^G]ǦϰUYi^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
<title>null d</title>
</head>

<body>
<h2 align=center>null d</h2>
<hr>

<pre>
<script>
x=null;
//x=Null;
//x=NULL;
//WC|{Lk~AJavaScript|۰ʤ_AGiHҩ~gk
document.writeln("x=null");
document.writeln("Tgk nullAD Null  NULL!");
document.writeln("x AG"+typeof(x));
document.write("null uȫAG");		//bifP_false
(x)?document.writeln("True!"):document.writeln("False!");
document.write("x==null O_ߡG");		//iHϥ==
(x==null)?document.writeln("True!"):document.writeln("False!");
</script>
</pre>

<hr>
</body>
</html>


JavaScript {]pPΡGΩΤ