zoukankan      html  css  js  c++  java
  • JS高级 — 函数的声明和表达式

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset="utf-8">
     5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     6 <title>函数的角色</title>
     7 </head>
     8 <body>
     9     <script>
    10         // 二、函数声明 & 函数表达式的区别
    11         // 函数声明
    12         // if (true) {
    13         //     function f1(){
    14         //         console.log("jjjjjjjj");
    15         //     }
    16         // } else{
    17         //     function f1() {
    18         //         console.log("ggggggg");
    19         //     }
    20         // }
    21         // f1(); //jjjjjjj
    22         
    23         var ff;
    24         if (true) {
    25             ff = function(){
    26                 console.log("jjjjjjjj");
    27             }
    28         } else {
    29             ff = function() {
    30                 console.log("ggggggg");
    31             }
    32         }
    33         ff();
    34 // 函数声明如果放在if-else语句中 在IE8的浏览器中会出现问题
    35 // 建议使用 函数表达式
    36 
    37         // 一、函数的角色
    38         // 1、函数的声明
    39         function fun(){
    40             console.log("我是函数声明!");
    41         }
    42         // 使用
    43         fun(); 
    44         // 2、函数表达式
    45         var ff = function(){
    46             console.log("我是函数表达式!");
    47         };
    48         // 使用
    49         ff();  
    50        
    51         
    52     </script>
    53 </body>
    54 </html>
  • 相关阅读:
    Android 程序员必须知道的 53 个知识点
    2017.8.27 考试
    hdu 3118 Arbiter
    UVA 1575 Factors
    [HNOI2008]Cards
    JSOI2008 小店购物
    hdu 2121 Ice_cream’s world II
    poj 3164 Command Network(最小树形图模板)
    [USACO14MAR] Counting Friends
    UVA 10479 The Hendrie Sequence
  • 原文地址:https://www.cnblogs.com/sylys/p/11578487.html
Copyright © 2011-2022 走看看