JavaScript基本类型
?
一.布尔型
?
二.字符串型
?
三.数值型
?
四.函数
??
附源代码:
?
1.布尔型?
<!DOCTYPE HTML PUBLIC "-//W 3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>JavaScript Boolean型测试</title> </head> <body> <div align="center"> <B>布尔型</B></div><br> <table align="center" border="1" width="70%"> <tr> <th>序号</th> <th>表达式</th> <th>值</th> </tr> <tr> <td>1</td> <td>+true</td> <td><input id=res1></input></td> </tr> <tr> <td>2</td> <td>+false</td> <td><input id=res2></input></td> </tr> <tr> <td>3</td> <td>parseInt(true)</td> <td><input id=res3></input></td> </tr> <tr> <td>4</td> <td>parseInt(false)</td> <td><input id=res4></input></td> </tr> <tr> <td>5</td> <td>true + ""</td> <td><input id=res5></input></td> </tr> <tr> <td>6</td> <td>false + ""</td> <td><input id=res6></input></td> </tr> <tr> <td>7</td> <td>new Boolean(true)</td> <td><input id=res7></input></td> </tr> <tr> <td>8</td> <td>new Boolean(false)</td> <td><input id=res8></input></td> </tr> <tr> <td>9</td> <td>new Boolean("true")</td> <td><input id=res9></input></td> </tr> <tr> <td>10</td> <td>new Boolean("false")</td> <td><input id=res10></input></td> </tr> <tr> <td>11</td> <td>true == "0"</td> <td><input id=res11></input></td> </tr> <tr> <td>12</td> <td>false == "0"</td> <td><input id=res12></input></td> </tr> <tr> <td>13</td> <td>true == "1"</td> <td><input id=res13></input></td> </tr> <tr> <td>14</td> <td>false == "1"</td> <td><input id=res14></input></td> </tr> </table> <table align="center" border="0" width="70%"> <button id=calculateResult onClick="calculateResult(this.form)">生成结果</button> </table> </body> </html> <script> function calculateResult() { res1.value = +true; res2.value = +false; res3.value = parseInt(true); res4.value = parseInt(false); res5.value = true + ""; res6.value = false + ""; res7.value = new Boolean(true); res8.value = new Boolean(false); res9.value = new Boolean("true"); res10.value = new Boolean("false"); res11.value = true == "0"; res12.value = false == "0"; res13.value = true == "1"; res14.value = false == "1"; } </script>
?
2. 字符串型
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>JavaScript Character型测试</title> </head> <body> <div align="center"> <B>字符串型</B></div><br> <table align="center" border="1" width="70%"> <tr> <th>序号</th> <th>表达式</th> <th>值</th> </tr> <tr> <td>1</td> <td>parseInt("1.2")</td> <td><input id=res1></input></td> </tr> <tr> <td>2</td> <td>parseInt("1.2 ")</td> <td><input id=res2></input></td> </tr> <tr> <td>3</td> <td>parseInt(" 1.5")</td> <td><input id=res3></input></td> </tr> <tr> <td>4</td> <td>parseInt("1.2XX")</td> <td><input id=res4></input></td> </tr> <tr> <td>5</td> <td>parseInt("0xff")</td> <td><input id=res5></input></td> </tr> <tr> <td>6</td> <td>parseInt("010")</td> <td><input id=res6></input></td> </tr> <tr> <td>7</td> <td>parseInt("str")</td> <td><input id=res7></input></td> </tr> <tr> <td>8</td> <td>parseInt(".1")</td> <td><input id=res8></input></td> </tr> <tr> <td>9</td> <td>parseFloat(".1")</td> <td><input id=res9></input></td> </tr> <tr> <td>10</td> <td>"str" == new String("str")</td> <td><input id=res10></input></td> </tr> <tr> <td>11</td> <td>"str" === new String("str")</td> <td><input id=res11></input></td> </tr> <tr> <td>12</td> <td>"" ? true:false</td> <td><input id=res12></input></td> </tr> <tr> <td>13</td> <td>"0" ? true:false</td> <td><input id=res13></input></td> </tr> <tr> <td>14</td> <td>"str" ? true:false</td> <td><input id=res14></input></td> </tr> <tr> <td>15</td> <td>"" == 0</td> <td><input id=res15></input></td> </tr> <tr> <td>16</td> <td>"0" == false</td> <td><input id=res16></input></td> </tr> <tr> <td>17</td> <td>"1.2" == 1.2</td> <td><input id=res17></input></td> </tr> </table> <table align="center" border="0" width="70%"> <button id=calculateResult onClick="calculateResult(this.form)">生成结果</button> </table> </body> </html> <script> function calculateResult() { res1.value = parseInt("1.2"); res2.value = parseInt("1.2 "); res3.value = parseInt(" 1.5"); res4.value = parseInt("1.2XX"); res5.value = parseInt("0xff"); res6.value = parseInt("010"); res7.value = parseInt("str"); res8.value = parseInt(".1"); res9.value = parseFloat(".1"); res10.value = "str" == new String("str"); res11.value = "str" === new String("str"); res12.value = "" ? true:false; res13.value = "0" ? true:false; res14.value = "str" ? true:false; res15.value = "" == 0; res16.value = "0" == false; res17.value = "1.2" == 1.2; } </script>
?
?
3. 数值型
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>JavaScript Number型测试</title> </head> <body> <div align="center"> <B>数值型</B></div><br> <table align="center" border="1" width="70%"> <tr> <th>序号</th> <th>表达式</th> <th>值</th> </tr> <tr> <td>1</td> <td>1.2 + ""</td> <td><input id=res1></input></td> </tr> <tr> <td>2</td> <td>NaN + ""</td> <td><input id=res2></input></td> </tr> <tr> <td>3</td> <td>isNaN("1.2")</td> <td><input id=res3></input></td> </tr> <tr> <td>4</td> <td>isNaN("1.2 ")</td> <td><input id=res4></input></td> </tr> <tr> <td>5</td> <td>isNaN("1.2XXX")</td> <td><input id=res5></input></td> </tr> <tr> <td>6</td> <td>NaN == NaN</td> <td><input id=res6></input></td> </tr> <tr> <td>7</td> <td>(0.1+0.2) == 0.3</td> <td><input id=res7></input></td> </tr> <tr> <td>8</td> <td>1 == true</td> <td><input id=res8></input></td> </tr> <tr> <td>9</td> <td>0 == false</td> <td><input id=res9></input></td> </tr> </table> <table align="center" border="0" width="70%"> <button id=calculateResult onClick="calculateResult(this.form)">生成结果</button> </table> </body> </html> <script> function calculateResult() { res1.value = 1.2 + ""; res2.value = NaN + ""; res3.value = isNaN("1.2"); res4.value = isNaN("1.2 "); res5.value = isNaN("1.2XXX"); res6.value = NaN == NaN; res7.value = (0.1+0.2) == 0.3; res8.value = 1 == true; res9.value = 0 == false; } </script>
?
?
4. 函数
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>JavaScript Function测试</title> </head> <body> <div align="center"> <B>函数</B></div><br> <table align="center" border="1" width="70%"> <tr> <th>序号</th> <th>表达式</th> <th>值</th> </tr> <tr> <td>1</td> <td>[] + ""</td> <td><input id=res1></input></td> </tr> <tr> <td>2</td> <td>[12,22,33] + ""</td> <td><input id=res2></input></td> </tr> <tr> <td>3</td> <td>+[]</td> <td><input id=res3></input></td> </tr> <tr> <td>4</td> <td>+[9]</td> <td><input id=res4></input></td> </tr> <tr> <td>5</td> <td>+[12,22,33]</td> <td><input id=res5></input></td> </tr> <tr> <td>6</td> <td>{} + ""</td> <td><input id=res6></input></td> </tr> <tr> <td>7</td> <td>+{}</td> <td><input id=res7></input></td> </tr> <tr> <td>8</td> <td>function(){}</td> <td><input id=res8></input></td> </tr> <tr> <td>9</td> <td>+function(){}</td> <td><input id=res9></input></td> </tr> <tr> <td>10</td> <td>new Date()</td> <td><input id=res10></input></td> </tr> <tr> <td>11</td> <td>+new Date()</td> <td><input id=res11></input></td> </tr> <tr> <td>12</td> <td>[] == 0</td> <td><input id=res12></input></td> </tr> <tr> <td>13</td> <td>[] == false</td> <td><input id=res13></input></td> </tr> <tr> <td>14</td> <td>[0] == false</td> <td><input id=res14></input></td> </tr> <tr> <td>15</td> <td>[] ? true:false</td> <td><input id=res15></input></td> </tr> <tr> <td>16</td> <td>[0] ? true:false</td> <td><input id=res16></input></td> </tr> </table> <table align="center" border="0" width="70%"> <button id=calculateResult onClick="calculateResult(this.form)">生成结果</button> </table> </body> </html> <script> function calculateResult() { res1.value = [] + ""; res2.value = [12,22,33] + ""; res3.value = +[]; res4.value = +[9]; res5.value = +[12,22,33]; res6.value = {} + ""; res7.value = +{}; res8.value = function(){}; res9.value = +function(){}; res10.value = new Date(); res11.value = +new Date(); res12.value = [] == 0; res13.value = [] == false; res14.value = [0] == false; res15.value = [] ? true:false; res16.value = [0] ? true:false; } </script>
?
?
?