skip to Main Content

Javascript – Javasript closure stange behaviour

emphasized textHi I'm learning Javascripts closures and tjis code beahves funny to me: function Unique_id2() { let counter = 0; function f() { return counter++; }; return f(); } console.log("UID2"); let f = Unique_id2; console.log(typeof f); console.log(f()); console.log(f()); console.log(f()); console.log(f());…

VIEW QUESTION

Javascript – Closures and Events

I am learning JavaScript. I was practicing applying closures but I got stuck and am not able to find the issue with my code. function change_greeting() { let on_or_off = 1; return function button() { if (on_or_off) { document.getElementById("demo") =…

VIEW QUESTION
Back To Top
Search