I don't have much experience with javascript and I have been looking for an explanation into this syntax so if you know it would be much appreciated if you can help me understand it!
In Node.js
const { check, validationResult } = require('express-validator/check');
const { matchedData, sanitize } = require('express-validator/filter');
I am used to declaring variables like this:
const name = require('npm-module..');
Could someone explain this to me?
It is called destructuring assignment.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
You are basically telling JS that require statement will return an object, and if it can pull out for you the property
check and validationResult in 2 const with the same name.
The syntax can go deeper with assigning default values or pulling out nested objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With