• 认识语句和符号,良好编程习惯加分号


    认识语句和符号

    JavaScript语句是发给浏览器的命令。这些命令的作用是告诉浏览器要做的事情。

    每一句JavaScript代码格式: 语句;

    先来看看下面代码

    <script type="text/javascript">
       alert("hello!");
    </script>

    例子中的alert("hello!");就是一个JavaScript语句。

    一行的结束就被认定为语句的结束,通常在结尾加上一个分号";"来表示语句的结束。

    看看下面这段代码,有三条语句,每句结束后都有";",按顺序执行语句。

    <script type="text/javascript">
       document.write("I");
       document.write("love");
       document.write("JavaScript");
    </script>

    注意:

    1. “;”分号要在英文状态下输入,同样,JS中的代码和符号都要在英文状态下输入。

    2. 虽然分号“;”也可以不写,但我们要养成编程的好习惯,记得在语句末尾写上分号。


    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>认识语句</title>
    <script type="text/javascript">
        document.write("Hello");
        document.write("world");
    </script>
    </head>
    <body>
    </body>
    </html>


  • 相关阅读:
    RTP/RTSP编程
    makefile
    VS 2010内存泄漏检测
    Linux Shell中捕获CTRL+C
    const
    Hdu 5344
    Hdu5762
    CF1200C
    CF1200B
    CF1200A
  • 原文地址:https://www.cnblogs.com/yongbin668/p/5592838.html
Copyright © 2020-2023  润新知