LoginSignup
1
0

More than 1 year has passed since last update.

[JavaScript] functionとアロー関数の違い

Posted at

function

function showNameFunction() {
  this.name = 'wadayamada';
  console.log(this);
}

showNameFunction();

Output

<ref *1> Object [global] {
  global: [Circular *1],
  clearInterval: [Function: clearInterval],
  clearTimeout: [Function: clearTimeout],
  setInterval: [Function: setInterval],
  setTimeout: [Function: setTimeout] {
    [Symbol(nodejs.util.promisify.custom)]: [Function (anonymous)]
  },
  queueMicrotask: [Function: queueMicrotask],
  clearImmediate: [Function: clearImmediate],
  setImmediate: [Function: setImmediate] {
    [Symbol(nodejs.util.promisify.custom)]: [Function (anonymous)]
  },
  name: 'wadayamada'
}

アロー関数

const showNameArrowFunction = () => {
  this.name = 'wadayamada';
  console.log(this);
};

showNameArrowFunction();

Output

{ name: 'wadayamada' }
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0