前言

我是歌谣 最好的种树是十年前 其次是现在 今天继续给大家带来的是this指向的讲解

环境配置

npm init -y
yarn add vite -D

修改page.json配置端口

{
  "name": "demo1",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "vite --port 3002"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "vite": "^4.4.9"
  }
}

案例1

function test(a=1,b){
    console.log(a)
    console.log(b)
}
test(undefined,2)

运行结果

前端歌谣-第贰拾贰课-函数参数默认值_环境配置

案例2

function test(a,b){
    var a=arguments[0]||1;
    var b=arguments[1]||2;
    console.log(a)
    console.log(b)
}
test(undefined,2)

运行结果

前端歌谣-第贰拾贰课-函数参数默认值_前端_02

案例3

function test(a, b) {
    var a, b;
    if (typeof (arguments[0] !== 'undefind')) {
        a = arguments[0]
    } else {
        a = 1
    }
    if (typeof (arguments[1] !== 'undefind')) {
        b = arguments[1]
    } else {
        b = 2
    }
    console.log(a)
    console.log(b)
}
test(2, 3)

运行结果

前端歌谣-第贰拾贰课-函数参数默认值_json_03


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6