Posts

Showing posts from November, 2018

What is the difference between save and save-dev?

Today we are going to go over something i’ve wanted to clarify for awhile, the difference between devDependencies and dependencies. When using NPM, the first thing to do is an npm init , which will set up a  package.json  file for us based off our answers to its survey. This  package.json  describes our module, and in it we can see a list of all installed dependencies and devDependencies that we have installed and added to our project. The difference between these two, is that devDependencies are modules which are only required during development, while dependencies are modules which are also required at runtime. To save a dependency as a devDependency on installation we need to do an  npm install --save-dev , instead of just an  npm install --save.  A nice shorthand for installing a devDependency that I like to use is  npm i -D . The shorthand for saving a regular dependency is  -S  instead of  -D . Some good examples of dependencies which would be required at runtime includ

What's the difference between a tilde (~) and a caret (^) in a npm package.json file?

If you use npm to manage packages in your JavaScript application, you’re probably familiar with the package.json file. { "devDependencies": { "ember-cli": "~2.14.0" } } The syntax is in JSON format where the key is the name of the package and the value is the version of the package to be used. npm uses the package.json file to specify the version of a package that your app depends on. The version number is in  semver syntax  which designates each section with different meaning. semver is broken into three sections separated by a dot. major.minor.patch 1.0.2 Major, minor and patch represent the different releases of a package. npm uses the tilde (~) and caret (^) to designate which patch and minor versions to use respectively. So if you see  ~1.0.2  it means to install version  1.0.2  or the latest patch version such as  1.0.4 . If you see  ^1.0.2  it means to install version  1.0.2  or the latest minor or patch version such

ES6 — Set vs Array — What and when?

ES6 — Set vs Array —  What and when? Set VS Array What is Set and what is Array? Everyone who works with JS until now is familiar with  Array  ( don’t tell me you don’t ). But what exactly is  Array ? Well, in general,  Array  is type of structure representing  block of data (numbers, objects, etc…)  allocated in consecutive memory. Example: [1,2,3,2] How about Set? Set , more familiar as a Math concept, is an  abstract data type  which contains  only distinct  elements/objects  without   the need of being allocated orderly by index. Example: {1,2,3} Yup, by definition, Array and Set are technically  different concepts . One of the biggest differences here, you may notice, is that  elements in Array can be duplicate  (unless you tell it not to be), and  in Set, they just can’t (regardless what you decide). In addition,  Array  is considered as “ indexed collection ” type of data structure, while  Set  is considered as “ keyed collection ”. A qui