JavaScript Data Types, and Error Handling with a little bit of ES6

typeof(1); // numbertypeof(‘1’); // stringtypeof(true); // booleantypeof({index: value}); // object
try {    // your code…} catch (error) {    // error handling}
try{ 
const value = 1;
console.log(value); // 1 console.log(“try executed”); // try executed} catch(error){console.log(error);}
try{ 
const value = 1;
console.log(x); console.log(“try executed”);} catch(error){ console.log(error.message); // x is not defined}
try{ 
const value = 1;
If (value > 0){ throw new SyntaxError( ‘your value is greater than 0’ ); }} catch(error){ console.log(error.message); // your value is greater than 0}
  • Variable Declaration — In ES6, you can declare JS variables by using const and let. Const means constant so that the variable will be static, and you can’t change it. And let uses when you need to change the value of a variable in your code.
if (true) { const variable = 1; }
  • Arrow Function — ES6 introduced arrow function to us. So you don’t have to use the function word in your code. Though you have to declare as a variable while using it.
const add = (x, y) => x + y ;const add = () => 1+1 // 2
  • Loops — Generally, if you declare a variable as var in for loop iteration, you can access the variable outside of the loop or bindings. So to optimize this, you have to use let while declaring a variable. Like this
for ( let i = 0; i < 5; i++) {codes}
if (condition){   \\  your codes here}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to host Angular + Express (API) on firebase free hosting.

ES6: a definitive Guide to the top

How to run queries in a transaction on nest.js with TypeORM

“this” Is Our Future

Face Recognition with Javascript

Photo taken by Hitesh Choudhary

CRUD Operations, JWT, MongoDB, MySQL, Aggregation, Node JS, Express JS

Leetcode Q421. Maximum XOR of Two Numbers in an Array

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Al-Junaed Islam

Al-Junaed Islam

More from Medium

Yet another interview question deep dive: Intersection of Two Arrays

Knowing Partials in Typescript

Binary Search Tree in JavaScript - (Implementation, Traversing, Formulas)

Is the experience card really that meaningful in computer programming?