All the fundamental you need to know in JavaScript

Tasnim Ahmed
3 min readMay 7, 2021

In my previous blog, I have told about what javaScript is. (click)

JavaScript is a lightweight, interpreted, object-oriented language with first-class functions, and is best known as the scripting language for Web pages.
Today we will discuss some fundamental topics in JavaScript.

Data Type:

In Javascript, there are two types of data. One is primitive and another one is Object. The five most basic types of primitive data are-> strings, numbers, booleans, undefined, and null. Open your editor and print these primitive values using console.log():

But We can do any code like what can change them.

There is also a complex data type name Object. The there most basic types of Objectdata are-> Array, Object, and Function. Object and Functions are also values but they are not like primitive. Open your editor and print these primitive values using console.log():

Js Objects

In JavaScript, an object is a standalone entity, with properties and type. Compare it with a car, A car is an object, with properties. It has a color, a design, weight, a material, it is made of, wheels, etc.

Example
var myCar = {
make: 'Ford',
model: 'Mustang',
year: 1969
};

JavaScript Functions

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 the function keyword. I will discuss functions in detail and their parameters in a different article sometime.

Example
function functionName(name) {
return name + name;
}

Js Error Handling using try…catch

If you are an experienced programmer or a beginner you have to face error no matter how much experience you are,

Usually, the script dies immediately if the code has an error. But there’s a syntax construct try...catch that allows us to “catch” errors so the script can be interpreted, instead of dying

When an error occurs, JavaScript generates an object containing the details about it. The object is then passed as an argument to catch:

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

Try…catch error property

The Error object has three properties:

  • message: a string with the error message.
  • name: the error's type.
  • stack: a stack trace of functions execution.
Example:
try {
name; // error, variable is not defined!} catch (err) {alert(err.name);// ReferenceErroralert(err.message); // lalala is not definealert(err.stack);
}

When try…catch does not work

Try is not work for a syntax error.
It's not worked for setTimeout function
If you declare a function in try{} then it will not work, you should place try…catch into the function

--

--

Tasnim Ahmed
0 Followers

Hello, I'm Tasnim Ahmed, a Front-End Developer . My core skill is based on JavaScript and React Js and I love to do most of the things using JavaScript.