Posts

Showing posts from 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 ...

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 min...

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...

ES6 arrow functions, syntax and lexical scoping

ES2015 (ES6) introduces a really nice feature that punches above its weight in terms of simplicity to integrate versus time saving and feature output. This feature is the arrow function. Before we dive into the features of the arrow function and what it actually does for us, let’s understand what an arrow function is  not . It’s not a replacement for the  function  keyword, at all. This means you can’t do a find and replace on every single  function  keyword and everything works perfectly, because it likely won’t. Table of contents Syntax Hint: arrows are anonymous Syntax: single line expressions Syntax: single argument functions Functionality: lexical scoping “this” If you’re competent with the way  JavaScript scope  works, and have a great understanding of lexical scope, the  this  keyword and Prototype methods such as  .call() ,  .apply()  and  .bind() , then you’re in good hands to continue reading. ...