DEV Community

Cover image for what is closure in javascript?
Arul .A
Arul .A

Posted on

what is closure in javascript?

Today I learn what is closure in JavaScript, I have search many contents and videos and finally they defines to create a nested function create a outer function and create the inner function and you will use the outer function in the inner function it can accessible.

Example:

function titles(){
       outervariable="vi"
      function subtitle(){
               let innervariable="jay"
               console.log(outervariable+innervariable)
       }
       return subtitle()
}

const name1=titles();
name1
Enter fullscreen mode Exit fullscreen mode

Top comments (0)