javascript 箭头功能(ES2015)ES6

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 箭头功能(ES2015)ES6相关的知识,希望对你有一定的参考价值。

const name = "Andrew";

const sayName = () => {
    const message = "My name is " + name;
    console.log(message);
}

sayName();

const sayBye = () => {
  console.log("Bye " + name);  
}

sayBye();
const square = (x) => {
    return x * x;
}

const cube = (x) => {
    return square(x) * x;
}
const multiply = (x, y) => {
    return x * y;
}

const add = (a, b) => {
    return a + b;
}

const subtract = (a, b) => {
    return a - b;
}
//Function Declaration

function divide1(a, b) {
  return a / b; 
}

//Function Expression

const divide2 = function(a, b) {
  return a / b;
}

//Arrow Function Expression

const divide3 = (a, b) => {
  return a / b;
}

//Arrow Function Expression - concise

const divide4 = (a, b) => a / b;

以上是关于javascript 箭头功能(ES2015)ES6的主要内容,如果未能解决你的问题,请参考以下文章