android internet tech

javascript: Enable optional chaining in Node app by using Babel

Instructor: 0:00 In a Node app, we will get entry to Object (*4*) using dot notation in JavaScript. However, if a assets’s dad or mum does not exist, JavaScript will throw an error. To safeguard ourselves in case of having access to participants of non-existent homes, we will use Optional Chaining.

0:21 Optional Chaining is level 4 ECMAScript proposal. In a Node app, we will use Optional Chaining by using Babel. (*7*) setting preset lets in us to make use of newest JavaScript options in Node.

0:35 We’ll first set up @babel/preset-env core Node in CLI modules. Then, we can allow Babel by letting it assemble our JavaScript, and level our npm get started script to run the compiled JavaScript. We’ll additionally allow a preset proper right here.

0:57 In our Node app, let’s get entry to a assets that does not exist by using optional chaining. As we will see, the result’s undefined, which means that we’re set to make use of optional chaining in Node app. To be sure that Babel is operating accurately, we will additionally get entry to a assets that exists, and the result’s 7, as we anticipated.