You need to Know About JavaScript- Part Two

Js Hoisting

Block-Level Declarations

Understanding of JS Primitive

Js Objects

Js Functions

JS Coding Style

Curly Braces

if (condition) {
// do this
// …and that
// …and that
Other Practice you should try
(Good) if (n < 0) alert(`Power ${n} is not supported`); //No braces needed before alert
(Bad) if (n < 0)
alert(`Power ${n} is not supported`); //Bad practice, use braces before alert
aligned, // 5 spaces padding at the left
) { // ... }

JS Comment

// This code will do this thing (...) and that thing (...) 
// ...and who knows what else...
code complex;
* Returns x raised to the n-th power.
* @param {number} x The number to raise.
* @param {number} y The power, must be a natural number.
* @return {number} x raised to the n-th power.
function myFunction(x, y) { ... }

Js Error Handling using try…catch

try {
// code…} catch (err) {// error handling}

Try…catch error property

  • message: a string with the error message.
  • name: the error's type.
  • stack: a stack trace of functions execution.
try {
lalala; // error, variable is not defined!} catch (err) {alert(; // ReferenceErroralert(err.message); // lalala is not definedalert(err.stack); // ReferenceError: lalala is not defined at ( stack)// Can also show an error as a whole// The error is converted to string as "name: message"alert(err); // ReferenceError: lalala is not defined}

JSON Error handling using try…catch

let json = "{ bad json }";
try {let user = JSON.parse(json); // <-- when an error occurs...alert( ); // doesn't work} catch (err) {// ...the execution jumps herealert( "Our apologies, the data has errors, we'll try to request it one more time." );alert( );alert( err.message );}



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
Rajibul Hasan

Rajibul Hasan

I am a curious Programmer and Full-Stack Web Developer. My passion is coding and love to share my knowledge and experience with others.