More JavaScript concepts to know

MD. Razaul Haque Subho
3 min readMay 6, 2021

Exceptions -

Coding is something that is not definite. This means it is very unlikely to smoothly run through all the way to the output unless you are exceptions. Every developer, programmer faces error while developing something. While getting errors you must be out of your mind after seeing a bunch of lines in red, indicating something you are almost unaware of. There comes Error handling to gently handling all the error and make a statement about what exactly the problem is about. Almost every modern language has these exception terms handled in the same way and JavaScript is indifferent to it.

Coming to JavaScript, exception handling is just like traditional:

try{} catch (err){}
finally{
}

Catch -The catch statement lets you handle the error.

Try -The throw statement lets you create custom errors.

Finally — The finally statement lets you execute code, after try and catch, regardless of the result.

Event Loop -The Event Loop is a queue of callback functions. When an async function executes, the callback function is pushed into the queue. The JavaScript engine doesn’t start processing the event loop until the code after an async function has executed.
Theoretically, event-driven programming is application flow control that is based on events or changes in state.

Caching

The act of keeping data in storage to allow retrieval without having to request the data from the original source, if that data will not change frequently.

A typical caching scenario is having a cached copy of a web page. That page doesn’t change every five minutes, so caching it locally on your computer saves time and bandwidth for you to re-display it if you hit reload in your browser.

The cache is generally much faster than loading from disk or having a server generate a page from scratch. There are many other caches such as a database cache, or a disk cache, that speed up access for all kinds of events.

Client-Side Caching — Client-side caches are usually used to avoid transferring the same data over the network repeatedly.

Server-Side Caching — Server-side caches are generally used to avoid making expensive database operations repeatedly to serve up the same content to lots of different clients.

Javascript primitive and non-primitive datatypes

Primitives — Primitives are known as being immutable data types because there is no way to change a primitive value once it gets created.

var string = ‘This is a string.’;string[1] = ‘H’console.log(string) // ‘This is a string.’

Primitives are compared by value. Two values are strictly equal if they have the same value.

var number1 = 5;
var number2 = 5;
number1 === number 2; //
truevar string1 = ‘This is a string.’;
var string2 = ‘This is a string.’;
string1 === string2; // true

Non-primitive values are mutable data types. The value of an object can be changed after it gets created.

var arr = [ ‘one’, ‘two’, ‘three’, ‘four’, ‘five’ ];arr[1] = ‘TWO’;console.log(arr) // [ ‘one’, ‘TWO’, ‘three’, ‘four’, ‘five’ ];

Objects are not compared by value. This means that even if two objects have the same properties and values, they are not strictly equal. The same goes for arrays. Even if they have the same elements that are in the same order, they are not strictly equal.

var obj1 = { ‘cat’: ‘playful’ };var obj2 = { ‘cat’: ‘playful’ };obj1 === obj2; // falsevar arr1 = [ 1, 2, 3, 4, 5 ];var arr2 = [ 1, 2, 3, 4, 5 ];arr1 === arr2; // false

Non-primitive values can also be referred to as reference types because they are being compared by reference instead of value. Two objects are only strictly equal if they refer to the same underlying object.

var obj3 = { ‘car’ : ‘purple’ }var obj4 = obj3;obj3 === obj4; // true

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response