• JavaScript: function


    Define:

      函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块。

    Grammar:

      function functionname()
      {
        codes
      }

      Hint 

           函数数名称不要包含特殊字符。                      

      函数名字名称最好含义明确。                         

      函数名称最好遵循驼峰标记法或者下划线法。

      函数名称严格区分大小写。                             

    Example: 

    1 <script>
    2        alert(demo())         
    3        function demo(){      
    4            alert("this is a function")    //alert()是执行的一个代码段
    5            return 1                      
    6        }         
    7 </script>

    !  Hint :涵数名称如果重复会产生覆盖:

    <script>
          function demo(){
              alert("demo1")
          }
          function demo(){
              alert("demo2")
          }
          demo()         //Output:demo2
    </script>

    A function can have arguments or no arguments, can have one or more arguments。

    <script>
    
          function demo1(num1,num2){
              return  num1+num2   
          }
    
          function demo2(){
              return  5
          }
    
          alert(demo1(1.3))  //=>返回值为3
          alert(demo2())  //=>返回值为5
    
    </script>    

     





  • 相关阅读:
    5_添加购物车 View+Con
    5_添加购物车 B+M
    5_添加购物车 D
    登录注册V
    bootstrap-标题
    h5整理--详解css的相对定位和绝对定位
    各大门户网站的css初始化代码
    九月二十八JS验证
    js函数和运算符
    4.1原始表达式 9/16
  • 原文地址:https://www.cnblogs.com/chenzhihong294/p/9943691.html
Copyright © 2020-2023  润新知