JS之變數聲明

來源:互聯網
上載者:User

標籤:ber   9.png   聲明   javascrip   輸出   雙引號   document   back   png   

javascript的變數聲明:
格式:
  var 變數名 = 資料;


聲明變數要注意的事項:
  1. 在javascript中聲明變數是 使用var關鍵字聲明的,javascript中的變數可以儲存任意的資料類型資料.
  2. javascript中VARIANT 資料型別是根據儲存的值決定的,可以隨時更改儲存資料的類型。
  3. 定義了多個同名的變數是,後定義的同名變數是覆蓋前面定義的同名變數。
  4. 聲明變數的時候可以省略var關鍵字,但是不建議省略。


javascript的資料類型:

  typeof 查看變數的資料類型。

  使用格式:

    typeof 變數名

javascript的資料類型:

  number 小數與整數

  string 字串 注意: javascript中沒有字元的概念,只有字串,字串可以寫在單引號或雙引號中。

  boolean 布林值資料型別,

  undefined undefined代表該變數沒有定義。

<script type="text/javascript>"        document.write("10資料類型是"+(typeof 10)+"<br/>");    document.write("3.14資料類型是"+(typeof 3.14)+"<br/>");    document.write("a資料類型是"+(typeof ‘abc‘)+"<br/>");    document.write("abc資料類型是"+(typeof "abc")+"<br/>");    document.write("abc資料類型是"+(typeof true)+"<br/>");        document.write("aVARIANT 資料型別是"+(typeof a)+"<br/>");    </script>    

輸出:

JS之變數聲明

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.