Javascript 變數補充篇

來源:互聯網
上載者:User

      前面有一篇日誌是寫道有關JS變數的,這裡還寫JS變數。看例子:

<script type="text/javascript">var str='abcde';   var obj=new String(str);function newToString(){return 'Hello world!';}function func(val){val.toString=newToString;}//樣本1:傳入值func(str);alert(str);//樣本2:傳入引用func(obj);alert(obj);</script>
Tips:func(xxx);是修改值的。

      這樣如果難看一點,可以看看之前的那個差不多的例子:

var a = 3.14;  // Declare and initialize a variablevar b = a;     // Copy the variable's value to a new variablea = 4;         // Modify the value of the original variablealert(b)       // Displays 3.14; the copy has not changedvar a = [1,2,3];  // Initialize a variable to refer to an arrayvar b = a;        // Copy that reference into a new variablea[0] = 99;        // Modify the array using the original referencealert(b);         // Display the changed array [99,2,3] using the new reference

     變數聲明

     變數聲明有兩種方法:顯式和隱式。

     顯式一般是指使用Var聲明,隱式(即用即聲明)

    

//聲明變數var str='abc';//聲明函數function foo(){  str='abc';}//南明異常對象extry{  //...}catch(ex){  //...}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.