Blogger Information
Blog 12
fans 0
comment 0
visits 5357
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 实例演示四种常用的函数类型
汉邦
Original
491 people have browsed it

函数类型

  1. 命名函数: function
    代码演示:

    1. function sum(a,b){
    2. return a + b
    3. }
    4. console.log(sum(1,2));
  2. 匿名函数: fn = function (){}
    代码演示:

    1. const sum1 = function (a, b) {
    2. return `${a} + ${b} = ${a + b}`
    3. }
    4. console.log(sum1(1, 2))
  3. 箭头函数: fn = ()=>{}
    代码演示:

    1. sum2 = (a, b) => {
    2. return `${a} + ${b} = ${a + b}`
    3. }
    4. console.log(sum2(1,2))
  4. 立即执行函数: (function(){})()
    代码演示:

    1. let result = (function (a, b) {
    2. return `${a} + ${b} = ${a + b}`
    3. })(1, 2)
    4. console.log(result)

    数据类型

  5. 原始类型: string,number,boolean,null,undefined
    代码演示:

    1. console.log('php.cn', typeof 'php.cn')
    2. console.log(666,typeof 666)
    3. console.log(true, typeof true)
    4. console.log(null,typeof null)
    5. let a
    6. console.log(a, typeof a)

    浏览器效果:

  6. 引用类型: array,object,function

    1. // 1. 数组
    2. const arr = [10, 'admin', true]
    3. console.log(arr)
    4. // 访问其中一个值
    5. console.log(arr[1])
    6. // 正常判断数组类型的方式
    7. console.log(Array.isArray(arr))
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:没什么问题,继续加油
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post