Skip to main content

Posts

Showing posts with the label closure in JavaScript

Closure in JavaScript | lexical scope | lexical scope vs closure

A closure gives you access to an outer function's scope from an inner function. A closure is a function having access to the parent scope, even after the parent function has closed. See the live result:-  https://playcode.io/1941383 //Clousure var sum = function ( a ){       console . log ( "Live Clousure views - " + a );       var c = 2 ;       return function ( b ){         return a + b + c; //lexical scope       } } //this function execute two times - one is - sum(1) and other one is - sumAgain(3) //the value of a=1 and c=3 will be presist in the mermory. One call to sumAgain(3) then the result will be 6 (1+3+2) //that is called closure   var sumAgain = sum ( 1 ); //calling and set the value of a=1 and c=2 in the memorey console . log ( sumAgain ( 3 )); //calling with value b=3. Now the result will be 6

How To Convert a string to Lowercase?

To convert a string to lowercase -  To convert a string in JavaScript using the “toLowerCase()” method. The string length should be grater then zero. Example - let testStr = 'This is test string' ; testStr = testStr . toLowerCase (); console . log ( testStr ); //Output - This is test string ü   Stayed Informed –   Object Oriented JavaScript Interview Questions I hope you are enjoying with this post! Please share with you friends!! Thank you!!!

How To Create the Namespace in JavaScript?

Create the Namespace in JavaScript- You can see the below example in Detail- //AJAX Synchronous and Asynchronous Requests. //#REGION NAMESPACE var demo = demo || {}; //#ENDREGION demo . ajax = demo . ajax || ( function () {     var getBaseURL = function () {         var currentBaseURL = location . protocol + "//" + location . hostname +             ( location . port && ":" + location . port ) + "/" ;         return currentBaseURL ;     };     var baseURL = getBaseURL ();     var request_token ;     var ajaxAsyncCall = function ( requestURL , typeGP , inputs , request_token ) {         //Ajax Async CALL         $ . ajax ({    ...

What will be the output of the JavaScript code?

What will be the output of the code below? var abc = { x: 10 }; var result = ( function () {     delete abc.x;     return abc.x; })(); alert(result); Answers:-  The output would be “undefined”. The delete operator is used to delete the property of an object. Here “abc” is an object which has the property “x”. It's a “self-invoking” function and we will delete the x property from object “abc”. When you try to return a deleted property, it will return “undefined”. Stayed Informed – Best JavaScript Interview Questions & Answers I hope you are enjoying with this post! Please share with you friends. Thank you!!

What will be the output of the following code?

What will be the output of the following code? var abc = 10; var result = ( function () {     delete abc;     return abc; })(); alert(result); Answers:-  The output would be “ 10 ”. Here “abc” is a number type global variable and not an object. The “delete” operator is used to delete the property of an object so it will be “10”. Stayed Informed – Best JavaScript Interview Questions & Answers I hope you are enjoying with this post! Please share with you friends. Thank you!!

Countdown Timer jQuery Free Online [How To]

In this post, I am going to share the “ Countdown Timer ” using jQuery online live demo and code sample as well. Stayed Informed - jQuery OOPs Concepts Please see the detail & live demo as following, < script src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js" >< /script> < div id = "countdown" >< /div> < input type = "button" class = "button" value = "Start" id = "btnCountdownStart" /> < input type = "button" class = "button1" value = "Stop" id = "btnCountdownStop" /> < script type = "text/javascript" > var countdown = $( "#countdown" ).countdown360({ radius : 60 , seconds : 100 , label : [ "Sec" , "Seconds" ], fontColor : "#FFFFFF" , autostart : ! 1 , onComplete : function () { ...

“Happy New Year” Count Down [JavaScript Code]

In this post, I am going to share the “ JavaScript ” code sample download link to get “ Happy New Year! ” Count down watch. Actually, I am using a JavaScript functions to calculate and execute automatically your upcoming “ NEW YEAR ” Remaining times [ DAYS – HOURS – MINUTES - SECONDS ]. You can see the result after click in the below mention demo link. Stay Informed – Demo Link… Try the “ Live examples ” of the code shown in this page. Examples as, <script> $( function () { var initializeWatchClock = function (id, endtime) { var clock = document .getElementById(id); var daysSpan = clock.querySelector( '.days' ); var hoursSpan = clock.querySelector( '.hours' ); var minutesSpan = clock.querySelector( '.minutes' ); var secondsSpan = clock.querySelector( '.seconds' ); var updateWatchClock = function () { var t = getTimeRemaining(endtime); ...