Searching...
2016年2月2日 星期二

JavaScript 小常識

全域變數 與 區域變數
Exsample1:
var  text = "global";            //全域變數
fuction checktext(){
     var text = "local";          //宣告一個同名區域變數
     document.write(text);   
}
checktext();                       //印出local


Exsample2:
var  text = "global";            //全域變數
fuction checktext(){
     text = "local";               //更改全域變數
     document.write(text);   
}
checktext();                       //印出local


運算子 == 與 ===

== : 是否相等 (equality)
=== : 是否相同 (identity)

Date物件
var now = new Date();  //當前的日期

var dates = new Date(2016,0,31); //表示2016年1月31日 
//在 Date中的月份 以0~11表示


1 意見:

 
Back to top!