DEV Community

Cover image for Understand Javascript Call, Bind, and Apply in the Simplest and Easy Way Possible!!πŸ”₯
Priyank Deep Singh
Priyank Deep Singh

Posted on

Understand Javascript Call, Bind, and Apply in the Simplest and Easy Way Possible!!πŸ”₯

We all know how much these Javascript methods are confusing to understand. But there is always a simple way to explain complex things. Close your eyes and imagine yourself in the vast universe! You have an amazing spaceship and you are on a mission to explore different planets in the universe πŸ’₯

On each planet, you have to collect energy crystals to power your spaceship, like we play in the game 'No Mans Sky'!! The energy crystals are in different shapes and sizes, and you have to add their values to see how much energy you have collected.

Let's start with Call:

"Call" is like giving a direct command to your spaceship computer to perform a specific task. In our case, you want to ask the computer to add the values of the energy crystals you have collected.

Here's an example of what that would look like in code:

Image description

With "Call," you can ask the computer to add the values of the energy crystals in a straightforward and direct way. The computer will instantly perform the task and give you the result.

Image description

Now let's move on to Bind:

"Bind" is like telling your spaceship computer ahead of time that you want to add the values of energy crystals, but also giving it one of the values.

Here's an example of what that would look like in code:

Image description

With "Bind," you can tell the computer ahead of time that you always want to add a specific value to the energy crystals, and the computer will remember that. The next time you want to add values, you can just give it the second value, and the computer will do the rest.

Finally, let's talk about Apply:

"Apply" is like giving your spaceship computer a group of values to add together, instead of giving them one by one.

Here's an example of what that would look like in code:

Image description

With "Apply," you can give the computer all the values of energy crystals at once, and the computer will add them up quickly and efficiently. This is a great option when you have a lot of values to add.

So, there you have it! With Call, Bind, and Apply, you can ask your spaceship computer to add the values of the energy crystals in different ways and complete your mission to explore the universe with ease!

Hope this was helpfull!!😊😊

Top comments (4)

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
priyankdeep78 profile image
Priyank Deep Singh

Thanks much!!

Collapse
 
kumarkalyan profile image
Kumar Kalyan

Great article @priyankdeep78

Collapse
 
priyankdeep78 profile image
Priyank Deep Singh

Thanks man!!