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}

--

--

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