It is the prevention of changing a value.
const numbers=[1,2,3,4,5,6]
numbers[0]=100;
numbers.reverse();
console.log(numbers);
[ 6, 5, 4, 3, 2, 100 ]
The use of const allows to modify the value but not the structure.
To facilitate the coding ESLint could be installed. Open a terminal and…
npm install --save-dev eslint
After that, the binary must be initialized
npm install --save-dev eslint
Several questions will appear
? How would you like to use ESLint? To check syntax, find pr
oblems, and enforce code style
? What type of modules does your project use? JavaScript mod
ules (import/export)
? Which framework does your project use? None of these
? Does your project use TypeScript? No
? Where does your code run? Browser
? How would you like to define a style for your project? Use
a popular style guide
? Which style guide do you want to follow? Airbnb: https://g
ithub.com/airbnb/javascript
? What format do you want your config file to be in? JavaScr
ipt
Checking peerDependencies of eslint-config-airbnb-base@lates
t
The config that you've selected requires the following dependencies:
eslint-config-airbnb-base@latest eslint@^5.16.0 || ^6.1.0 eslint-plugin-import@^2.18.2
? Would you like to install them now with npm? Yes
Installing eslint-config-airbnb-base@latest, eslint@^5.16.0 || ^6.1.0, eslint-plugin-import@^2.18.2
Ex_Files_Learning_Functional_Programming_JavaScript_ES6@1.0.
0 /home/ntala/Documents/Ex_Files_Learning_Functional_Programming_JavaScript_ES6
├─┬ eslint-config-airbnb-base@14.0.0
│ ├── confusing-browser-globals@1.0.9
│ └── object.entries@1.1.1
└─┬ eslint-plugin-import@2.20.0
├─┬ array-includes@3.1.1
│ └── is-string@1.0.5
├── array.prototype.flat@1.2.3
├── contains-path@0.1.0
├─┬ debug@2.6.9
│ └── ms@2.0.0
├─┬ doctrine@1.5.0
│ └── isarray@1.0.0
├─┬ eslint-import-resolver-node@0.3.3
│ └─┬ debug@2.6.9
│ └── ms@2.0.0
├─┬ eslint-module-utils@2.5.2
│ ├─┬ debug@2.6.9
│ │ └── ms@2.0.0
│ └─┬ pkg-dir@2.0.0
│ └─┬ find-up@2.1.0
│ └─┬ locate-path@2.0.0
│ └─┬ p-locate@2.0.0
│ └─┬ p-limit@1.3.0
│ └── p-try@1.0.0
├── object.values@1.1.1
└─┬ read-pkg-up@2.0.0
├─┬ find-up@2.1.0
│ └─┬ locate-path@2.0.0
│ └─┬ p-locate@2.0.0
│ └─┬ p-limit@1.3.0
│ └── p-try@1.0.0
└─┬ read-pkg@2.0.0
├─┬ load-json-file@2.0.0
│ ├── graceful-fs@4.2.3
│ ├─┬ parse-json@2.2.0
│ │ └─┬ error-ex@1.3.2
│ │ └── is-arrayish@0.2.1
│ ├── pify@2.3.0
│ └── strip-bom@3.0.0
├─┬ normalize-package-data@2.5.0
│ ├── hosted-git-info@2.8.5
│ └─┬ validate-npm-package-license@3.0.4
│ ├─┬ spdx-correct@3.1.0
│ │ └── spdx-license-ids@3.0.5
│ └─┬ spdx-expression-parse@3.0.0
│ └── spdx-exceptions@2.2.0
└─┬ path-type@2.0.0
└── pify@2.3.0
npm WARN Ex_Files_Learning_Functional_Programming_JavaScript
_ES6@1.0.0 No description
npm WARN Ex_Files_Learning_Functional_Programming_JavaScript
_ES6@1.0.0 No repository field.
Successfully created .eslintrc.js file in /home/ntala/Docume
nts/Ex_Files_Learning_Functional_Programming_JavaScript_ES6
Now the immutable plugin package should be installed:
npm install --save-dev eslint-plugin-immutable
add the rules to the eslint.js file
module.exports = {
env: {
browser: true,
es6: true,
},
extends: [
'airbnb-base',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: [
'immutable',
],
rules: {
'immutable/no-mutation': 2//error if it is found, warning is 1,0 is disabled
},
};
Set the directory where eslint will run.
npx eslint .
After this, all the errors and warnings should appear
Sources: https://www.linkedin.com/learning/learning-functional-programming-with-javascript-es6-plus