" several times , however I try to understand what this means...">

What does = = mean mean in node js

I am learning node js and have come across " =>" several times , however I try to understand what this means.

Here is an example:

app.post('/add-item', (req, res) => {
  // TODO: add an item to be posted
});

Do we really need this in the above example? A simple explanation would be helpful. Thanks

+4
source share
2 answers

It's nothing node-exclusive, it's an expression of the ES6 Arrow function

app.post('/add-item', (req, res) => {
  // TODO: add an item to be posted
});

basically means:

app.post('/add-item', function(req, res) {
  // TODO: add an item to be posted
});

The main difference between the two examples is that the former lexically relates meaning this.

+19
source

This is just another way of writing an anonymous function:

$(document).ready(() => {
    console.log('Hello I am typescript');
});

equivalent to javascript:

$(document).ready(function(){
    console.log('Hello I am typescript');
});
+1

Source: https://habr.com/ru/post/1653664/


All Articles