Difference between 'currying' and 'closure' in JavaScript?

So many time we got confused in currying and closure JavaScript functions just because both uses functions inside function.

So This is the answer of your question.

First I will explain What is closure in JavaScript ?

Creating a closure is nothing more than accessing a variable outside of a function's scope. Please note that a function inside a function isn't a closure. Closures are always use when need to access the variables outside the function scope.



Here is an example of closure function:

Answer will be 21. So here inside google function we are able to access the variable x which is outside the scope of the function google(). ...  Read More

Share This:


Laravel Call to undefined method Redis::connection()

The Redis class is built-in to Laravel and connection() is there. It can't be missing.  You might have installed php-redis on your system. Redis can be another class into php-redis. So there may conflict between Laravel Redis alias and another Redis class.

Now there are two solutions for solving this problem.

  1. You just need to edit your app config, open app/config/app.php and replace this line:

And then you can get your Redis instance like this:

2. Remove php-redis

To remove the php-redis you need to run the below command:

Now restart your Redis server by following command:

  ...  Read More

Share This:


Function return type in PHP 7 and void return type in PHP 7.1

One of the beautifull feature of programming languages came out in PHP 7 that now we also can have function return type in PHP like we have in other languages like Java, C, C# etc..
So PHP 7 adds support for return type declarations.
Now we can force a function to return a specific type of data.


In PHP 7 we have following function return types:
int : Integer data type.

float : Float data type.

array : Array data type.

bool : Boolean data type.

string: String data type.

Class/Interface name : Name of the class.

self : Instance of the same class. This can only be used if function is created under any class.

callable : Valid PHP callable.

 ...  Read More

Share This:


Currying functions in JavaScript | JavaScript currying function example

Currying is converting a single function of  arguments into  functions with a single argument each. So you can say Currying is a way to reduce functions of more than one argument to functions of one argument.

Here in Currying function we also uses the property of closures because we access the variables outside the scope of a function.

Here is and example of doing two number addition in JavaScript with simple function :

No if you write this with currying function in JavaScript :

Here is another which can give you more clarity on Currying function in JavaScript.

  ...  Read More

Share This:


Javascript closure function

Creating a closure is nothing more than accessing a variable outside of a function's scope. Please note that a function inside a function isn't a closure. Closures are always use when need to access the variables outside the function scope.

Closures mechanism is used to enable the data privacy.

Why is closures important?

  • Closures provide a way to associate data with a method that operates on that data.
  • They enable private variables in a global world.
  • Many patterns, including the fairly popular module pattern, rely on closures to work correctly.
  •  ...  Read More

Share This:


CRUD operation in Node, Express Js and Mongoose | Node Js CRUD tutorial

In most of the applications we do the same thing and that CRUD (Create, Read, Update and Delete). Today we are going to do the same but in Node Js where we are using MongoDB as a database.                   

If you wanted to start with Node Js believe me this article will make you life very easy in Node Js & Mongo DB.

Before starting I believe you installed Node Js, NPM, Express and MongoDB.

Here is the video where I have discussed the below functionality.

The below link will help you for creating a Node Js App. ...  Read More

Share This:


Middleware in Node Js & Express | How to create authentication Middleware in Node Js & Express

Express is an routing and middleware framework. And we use express to managing the routes and middlewares. Also it provides some folder structures.

Middleware is something which you wanted to execute before executing any particular function. For example we need a login check before accessing the user  dashboard and logout. That check is called middleware here.

In Express framework middleware has access to req (Request), res (Response) and next (Next route).

We validate the data through the request and if validation is true then return to the next action else we return to any URL like login using res (Response). ...  Read More

Share This:


Can we run a PHP file without a server or without a browser?

One word answer to this question is simply YES.

PHP is just a scripting language like others. Most of the people when hear about PHP, they think of websites first. But it can serve many other purpose. Of course it is actively and primarily being used for web development.

PHP is a server side scripting language, which means it runs on a server ( more precisely a web server). However one can write programs in PHP without having a web server at all.

Yes, by installing a CLI application you can print out the response in the terminal. ...  Read More

Share This:


Handling 404 with Angular 2 | How to handle 404 (page not found) page in Angular 2,4,5

How to handle the exception if user is trying to access the page which not found. I'm going to explain how to handle a page not found exception in Angular 2,4,5.

In you RouterConfig add the following below line:

And here is the whole route file.

For more information about routing in Angular 2,4,5 click here.

Share This: