Let’s talk about some confusing things about Javascript

Anisur Rahman Anik
3 min readMay 6, 2021
confusing

Today we will talk about some confusing thing about JavaScript

No matter how big a programmer is but the bug will never leave you. Bug and errors are an unwanted partner of a programmer. But there’s a syntax construct try...catch that allows us to “catch” errors so the script can, instead of dying, do something more reasonable.
The syntax of try-catch
try {

// code...

} catch (err) {

// error handling

}

Let’s talk about data types. There are mainly 3 categories of data types these are primitive, composite and special. String, Number and Boolean is called primitive. Array, Function and objects are called composite data types. Null and Undefined is special data types. Let’s know more about these
1.String: The Javascript String is an object that represents a sequence of characters. Javascript String holds only text values. Strings are enclosed with single or double quotes.
For Example :
var fName = “Anik”
var lName = “Munshi”
2.Number: Number is a primitive data type in Javascript. It holds only numeric values. It may be an integer, floating, hexadecimal, octal or exponential value.
For example :
let taka = 85000
3.Boolean: Boolean can have only two values true or false. Booleans are primitive data type.
For Example
let isIt = true
4.Array: Javascript Array is an object that represents a collection of similar type of elements. Normally arrays are used to store multiple data. Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations. Arrays are a composite data type.
Example:
let fruits = [‘banana’, ‘apple’, ‘orange’]
5.Function: In JavaScript, a function allows you to define a block of code, give it a name and then execute it as many times as you want. A JavaScript function can be defined using a function keyword.
For Example :
name function(param){
//////
}
name(arg)
6.Object: Object is a non-primitive data type in JavaScript. It is like any other variable, the only difference is that an object holds multiple values in terms of properties and methods. Properties can hold values of primitive data types and methods are functions.
Example:
let info = {name : ‘anik’, height : ‘5.6’, weight : 58}

Our code should be cleaner and human-readable because in future we may have to read that. We should follow the rules given below to have a cleaner code
1.In most JavaScript projects curly braces are written in “Egyptian” style with the opening brace on the same line as the corresponding keyword — not on a new line. There should also be a space before the opening bracket.
2.No one likes to read a long horizontal line of code. It’s best practice to split them.
3.A semicolon should be present after each statement, even if it could possibly be skipped.
4.Try to avoid nesting code too many levels deep.

--

--

Anisur Rahman Anik
0 Followers

A self-motivated and enthusiastic web developer with a deep interest in JavaScript.