Things you need to know: Type of values in JavaScript | try-catch | Clean and Easy Coding Style | Comments

Type of value in JavaScript

Javascript has 2 categories for values:

  • primitive value: the value which does not have any method or not an object. Which are used for math calculations(-15, 4, 9.8), for text(‘hello’), for adding unique property keys to an object(Unusual), for logical operation(true, false), for math on big numbers(new and Unusual), for unintentionally missing values, for intentionally missing values. example: number, string, symbol, boolean, bigInt, undefined, and null

After almost twenty-five years of studying JavaScript, scientists have only discovered a total of nine such types. The rest values are all objects. For example, even arrays, dates, and regular expressions fundamentally ​are​ objects in JavaScript.

Expression

we can ask any question answer from javascript using expression and it will return an accurate answer with value.

typeof()

using typeof(), we can know about a value’s type

Error handling: “ try-catch ”

when we are written a code for our need there will be a mistake, an unexpected user input, an erroneous server response, and many more errors occur. As a result, our script goes down or dies.

To handle these errors we need a functionality that will show us what kind of error is occurs from our scripts and why. So we use “ try-catch ” as a solution for this problem. syntax:

try{ // code here }

catch(error){ // handle error }

The basic functionality of “ try-catch ” is that “ try ” execute our code and if any kind of error happens “ catch ” will handle that error. Javascript has many built-in errors:

  • Error

we also can use the “ try-catch ” with the “ throw ” operator. syntax:

we can rethrow the error from the catch block.

Clean and Easy Coding Style :

To keep the script clean and easy is the art of programming. The person who can represent the complex task in a simple and easiest way is said to be a good programmer. like, use of proper space, Curly brace, understandable class name, understandable id name, multiple horizontal lines instead of long line, space between every new section line in code, Semicolons at the end of every code line, avoid nesting of code too many deep, to declare a function: declare function first then the code.

Comments

First of all, always try to write to code in a way that we need not comment but if need then the ways of comment in JavaScript:

  • single-line comment: //

I’m a junior front-end web developer.

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