1.NaN??
? ?1) NaN?屬性代表非數(shù)字值的特殊值.用于指示某個值不是數(shù)字.
? ?2) 方法parseInt()和parsefloat()再不能解析指定的字符串時就返回這個值.
? ?3) 用isNaN()判斷一個值是否是數(shù)字? ? ? ? 因為,NaN與所有值都不想等,包括它自己.
2.轉(zhuǎn)換規(guī)律
? ?1) if("")? 中 " "相當于false;任何非空的字符串,都可以在判斷中裝換為true
? ? 2)數(shù)字對象number,?除了NaN,+0和-0.其他都轉(zhuǎn)換為true.
? ??????????????alert(11>3);//true? ? ?//當運算符兩端 , 一端是數(shù)字,一端是其他類型時,
?????????????????其他類型會自動向數(shù)字類型轉(zhuǎn)換
????????????????alert("11">3);// true
????????????????alert(11>"3");//true
????????????????//字符串在進行比較時 ,規(guī)律是: 比較首字符asc碼. 如果一樣,比較第2位...
```
????????????????alert("11">"3");// false
????????????????alert("11">"1");// true
????????????????alert("abc">11);//false
```
? ? 3)null===>false? ? ?undefined===>false? ?因為因為undefined是null衍生出的,所以 ????????????????,alert(undefined == null);判斷結(jié)果為 true
3.函數(shù)function()
? ? 1)定義方式一
? ??????????函數(shù)對象的構(gòu)造方法中,最后一個參數(shù)是定義函數(shù)的體.之前所有參數(shù)都是定義函數(shù)的參? ? ? ?????????????????????數(shù)
? ??????????var fun2 = new Function("a","b","alert(a+b);");? ??
????????????調(diào)用方式:==>fun2( 1,5 );? ==>fun2( "1","5" );
? ? 2)定義方式二
? ??????????var fun3 = function (){
????????????????alert('bbb');
????????????}
? ? ? ? ? ? ? 調(diào)用方式:fun3();
? ? 3)定義方式三
? ??????????function fun1(){
????????????????????alert('aaa');
? ? ? ? ? ? ?}
? ? ? ? ? ? ?調(diào)用方式,直接顯示函數(shù)代碼:===>alert(fun1.toString());
? ? 4)函數(shù)的重載
? ??????js中函數(shù)的調(diào)用只看函數(shù)名稱.不看參數(shù)列表
? ??????function fun2(){
????????????????alert(arguments[0]); // 獲得第一個實際參數(shù)
????????}
????????//函數(shù)中的內(nèi)置對象 arguments
????????//arguments ==> 代表函數(shù)運行時的實際參數(shù)列表.
? ? ? ? 調(diào)用:
?????????fun2(); //0? undefined
????????fun2(1,2); //2 1
????????fun2(1,2,3); //3 1
????????// js中存在函數(shù)的重載嗎? 如何重載?
????????function fun3(){
????????????alert('aaa');
????????}
????????function fun3(a){
????????????alert('bbb');
????????}
????????//如上不能重載,是覆蓋
????????function fun4(){
????????????if(arguments.length == 2){
????????????????????alert(arguments[0]+arguments[1]);
????????????}else if(arguments.length == 3){
????????????????????alert(arguments[0]+arguments[1]-arguments[2]);
????????????}
????????}
? ? ? ? 調(diào)用方式:
????????fun4(1,2);//3
????????fun4(1,2,3);//0
????????//以上是重載.
5)return?void?的使用
? ? **1//使用return 關(guān)鍵字,返回內(nèi)容
????function fun2(a,b){
????alert('fun2');
????return a+b;
????}
? ? ?alert(fun2(1,2));//3
? ?**2 //return 關(guān)鍵字,在js中也可以作為結(jié)束方法運行的功能.
????function fun3(){
????????alert('aaa');
????????return ;
????????alert('bbb');
????}
4.parseInt()的使用? 和?Global對象
? ?**1 var str = "123abc";
????????//1.使用 +
????????//2.使用 new Number()
????????//3.parseInt
????????//alert(typeof parseInt(str));//number
?????????alert(+str); //NaN
????????alert(new Number(str));//NaN
????????alert(parseInt(str));// 123?
????????????//區(qū)別: 1,2兩種轉(zhuǎn)換屬于將字符串整體進行轉(zhuǎn)換.如果字符串中包含1個或以上轉(zhuǎn)換不了的 ????????????????????????字符,返回NaN
????????????????????????3 從左到右 依次轉(zhuǎn)換,能轉(zhuǎn)一個是一個,直到遇到不能轉(zhuǎn)換的值停止.
????????????????// parseFloat 轉(zhuǎn)換成浮點數(shù)
????????????????//與上面的parseInt一樣.區(qū)別是支持轉(zhuǎn)換小數(shù)
????????????????var str = "3.1415.9265357";
????????????????alert(parseInt(str));// 3
????????????????alert(parseFloat(str));//3.1415
**2.Globle對象
? ? 可理解為全局對象,也是已經(jīng)預(yù)定義好的對象
? ? 還有全局方法:decodeURI() ,encodeURI() ,?decodeURIComponent(),?encodeURIComponent(),isFinite(),?isNaN(),eval()
? ? 類似java中的靜態(tài)方法.
5.數(shù)組
? ? 1).創(chuàng)建方式
????????//1>創(chuàng)建方式1 創(chuàng)建一個數(shù)組并初始化值
????????var arr1 = ["abc",2,true,null,undefined,new Object()];
????????//2>創(chuàng)建方式2 同方式1
????????var arr2 = new Array(1,2,3);
????????//3>創(chuàng)建方式3 ==> 創(chuàng)建一個長度為3的數(shù)組. 數(shù)組Array的構(gòu)造函數(shù),如果只傳一個參數(shù),并且 ????????這個參數(shù)是整數(shù).那么這個整數(shù)就是數(shù)組的初始化長度.
????????var arr3 = new Array(3);
? ? 2)js中數(shù)組的特點:
????????//1.js中的數(shù)組,類型任意.
????????//2.數(shù)組的長度不是固定的.用到哪里,就有多長.
?????????????arr3[8] = 10;
????????????alert(arr3.length);//9
????????????alert(arr3[6]);//undefined?
? ? 3)方法
? ??????//sort方法 ==> 排序的方法.
????????//注意: 該方法默認排序規(guī)則,按照字符串規(guī)則排序.
????????//如果需要按照數(shù)字排序,需要準備一個比較器.
????????var arr5 = [2,9,3,100,5,7,1];
????????alert(arr5.sort(abc))//
????????//函數(shù)對象==> 比較器
????????function abc(a,b){
????????????/* if(a>b){
????????????????????return 1;
????????????}else if(a==b){
????????????????return 0;
????????????}else{
????????????????return -1;
????????????} */
????????????return a-b;
????????}
6.Date
? ??//Date對象
????/* 1.new Date() 獲取當前時間
????2.getFullYear() 獲取年份
????3.getMonth() 獲取月份注意 1月份結(jié)果為0
????4.getHours() 小時
????5.getDate() 日期
????6.getMinutes() 分鐘
????7.getSeconds() 獲取秒
????8.getTime()? 獲取毫秒值.
????9.toLocaleString() 獲取本地的時間格式字符串.
????10.getDay();獲得星期
????*/
????//空參構(gòu)造獲得當前時間
????var date = new Date();//當前時間
????//填入毫秒數(shù),獲得毫秒數(shù)對應(yīng)的時間
????var date2 = new Date(10000000000000);
????/* alert(date.getFullYear());//
????alert(date.getMonth());//
????alert(date.getHours());//
????alert(date.getDate());//
????alert(date.getMinutes());//
????alert(date.getSeconds());//
????alert(date.getTime());//
????alert(date.toLocaleString());//
????alert(date.getDay());// */
????//注意:
????//1.月份計數(shù)時是0~11月,所以要加1獲得正常月份
????//2.星期計數(shù)是 0~6 .
**科普一下**hc就是head count的縮寫,意指企業(yè)預(yù)計招聘的員工人數(shù)的意思策菜。
//Date對象
/* 1.new Date() 獲取當前時間
2.getFullYear() 獲取年份
3.getMonth() 獲取月份注意 1月份結(jié)果為0
4.getHours() 小時
5.getDate() 日期
6.getMinutes() 分鐘
7.getSeconds() 獲取秒
8.getTime()? 獲取毫秒值.
9.toLocaleString() 獲取本地的時間格式字符串.
10.getDay();獲得星期
*/
//空參構(gòu)造獲得當前時間
var date = new Date();//當前時間
//填入毫秒數(shù),獲得毫秒數(shù)對應(yīng)的時間
var date2 = new Date(10000000000000);
/* alert(date.getFullYear());//
alert(date.getMonth());//
alert(date.getHours());//
alert(date.getDate());//
alert(date.getMinutes());//
alert(date.getSeconds());//
alert(date.getTime());//
alert(date.toLocaleString());//
alert(date.getDay());// */
//注意:
//1.月份計數(shù)時是0~11月,所以要加1獲得正常月份
//2.星期計數(shù)是 0~6 .