Menu

Callback function JavaScript and NodeJS

Lets understand the callback fucntion in NodeJS using the below geocode example.

Here we have created geoCode function with two paramters, first parameter will take input of the location name and second parameter the function that needs to call. Similary, we can add or pass any number of paramters in fucntion as per need.

const geoCode = (location, callback) => {
    const data = {
        location: location,
        latitude: 0,
        longitude: 0
    }
    callback(data)
}

 

When we call the geoCode function, we are here passing a city name and second paramter a fucntion itself that print the return data from callback on console.
 
geoCode('New Delhi', (callbackData) => {
    console.log(callbackData)
});

Return

{ location: 'New Delhi', latitude: 0, longitude: 0 }

Immediately Invoked Function Expression (IIFE) in JavaScript

There is a situation where we want to make a function and execute that function immediately at the same place where we have written. These function can be written in JavaScript without any function name. The approach which we follow to do so is called Immediately Invoked Function Expression (IIFE). Let's see an example of this.

(function() {

//write something in IIFE

}

Hence, if a develop come to any point where there is no need to function name then they could use Immediately Invoked Function Expression (IIFE). 

How to write JavaScript function without function name? and Write an immediate invoke function in JavaScript?

Answer of all these questions is Immediately Invoked Function Expression. 

Type of Snakes

Snakes are a diverse group of reptiles that belong to the suborder Serpentes. They are found in various parts of the world and exhibit a wide range of physical characteristics, behaviors, and habitats. In this essay, we will explore some of the different types of snakes and highlight their distinct features.

1. Vipers:

Vipers are venomous snakes that can be found in both the Old World and the New World. They are characterized by their triangular-shaped heads and long, hollow fangs that inject venom into their prey. Vipers include species such as rattlesnakes, copperheads, and bushmasters. They typically have a heat-sensing pit organ between their eyes and nostrils, which aids in locating warm-blooded prey.

2. Cobras:

Cobras are another group of venomous snakes that are famous for their ability to expand their necks into a hood when threatened. They are found primarily in Africa and Asia. Cobras possess potent neurotoxic venom and can deliver a lethal bite. The King Cobra, the largest venomous snake in the world, belongs to this group.

3. Pythons:

Pythons are non-venomous constrictor snakes that are known for their impressive size and strength. They are found in tropical regions of Africa, Asia, and Australia. Pythons use their muscular bodies to suffocate and constrict their prey before swallowing it whole. The reticulated python and the Burmese python are among the largest snake species on Earth.

4. Boas:

Boas are large constrictor snakes that can be found in various parts of the world, including North, Central, and South America, as well as Africa, Asia, and some Pacific Islands. They have muscular bodies and are capable of consuming large prey. Boas give birth to live young, as opposed to laying eggs like many other snake species. The boa constrictor is a well-known representative of this group.

5. Colubrids:

Colubrids make up the largest family of snakes, with numerous species distributed worldwide. They exhibit great diversity in terms of size, coloration, and behavior. Some colubrids, such as the corn snake and the garter snake, are popular as pets due to their relatively docile nature and attractive patterns. Not all colubrids are harmless, though, as some species, like the boomslang and the mangrove snake, are venomous.

6. Sea Snakes:

Sea snakes are a unique group of venomous snakes adapted to marine environments. They are found predominantly in the waters of the Indian and Pacific Oceans. Sea snakes possess a flattened tail and a paddle-shaped tail, which allow them to swim efficiently. They can stay underwater for extended periods and feed on fish and other marine creatures.

These are just a few examples of the diverse types of snakes found around the world. Each group has its own set of characteristics, adaptations, and ecological roles. Whether venomous or non-venomous, snakes are fascinating creatures that have captured human curiosity for centuries. They play vital roles in their respective ecosystems and contribute to the overall biodiversity of our planet.


Related Articles:

Snakes in World
Snakes in Sea
Snakes in Mountain