Found 10711 Articles for Web Development

How does JavaScript .prototype work?

Shubham Vora
Updated on 22-Jul-2022 13:01:53

251 Views

In this example, we will learn how the prototype works in JavaScript. It is rare if a JavaScript developer doesn’t use the objects while developing the functions, and the objects can make a lot of work easy for developers.The prototype is also the advanced concept associated with the objects in JavaScript. Many of you have heard about the prototypes for the first time but don’t worry. We will cover all things about the prototypes in this tutorial.What does the prototype do?The prototype is the object created for every function class when the program starts execution. However, it depends on the ... Read More

How to turn a String into a JavaScript function call?

Smita Kapse
Updated on 03-Oct-2019 07:00:23

372 Views

To turn a string into a JavaScript function call, try to run the following codeExampleLive Demo                    function myFunction(argument) {             alert('My function ' + argument);          }          functionName = 'myFunction';          window[functionName]('is working.');          

Smart / self-overwriting / lazy getters in javaScript?

Shubham Vora
Updated on 15-Nov-2022 10:37:53

443 Views

In this tutorial, let us discuss the smart, self-overwriting, or lazy-getters in JavaScript. A getter binds the property of an object to a function, but the getter will not calculate the property value until we access it. The getter helps when we need to get some dynamic value without an explicit call. Users can follow the syntax below to work with the getters. Syntax { get prop() {} } { get [exp]() {} } The prop and the exp are the object's properties that bind to a function. 'prop' is a simple object property, and 'exp' is an expression. ... Read More

How can I execute JavaScript at the command prompt?

Shubham Vora
Updated on 22-Jul-2022 12:16:57

10K+ Views

This tutorial teaches us to execute JavaScript at the command prompt.JavaScript is the most popular language among programming languages that work with the browser. It is helpful to add the behaviors to the webpage and make it attractive. So, everyone can run JavaScript efficiently in the browser, but what if they want to run JavaScript via command prompt or other terminals.Here, we have different approaches to running JavaScript at the command prompt.Using the Node.jsOne of the most popular ways to run server-side JavaScript via command prompt is the use of Node.js. Node.js is the run time environment for JavaScript. The ... Read More

How to concatenate several strings in JavaScript?

Ramu Prasad
Updated on 09-Jan-2020 07:13:47

189 Views

To concatenate several string, use “Array.join()” method. Here, we will concat the following strings:John Amit SachinExampleYou can try to run the following code to concat several stringsLive Demo                    var arr = ['Amit', 'John', 'Sachin'];          document.write(arr.join(', '));            

Fire a JavaScript function when a user finishes typing instead of on key up?

Krantik Chavan
Updated on 16-Jun-2020 11:47:11

244 Views

To fire a JavaScript function when the user finishes typing, try to run the following code −Example                    var timer = null;          $("#myText").keydown(function(){             clearTimeout(timer);             timer = setTimeout(doStuff, 1000)          });          function doStuff() {             alert("Write more!");          }                

What are the best practices for function overloading in JavaScript?

Nitya Raut
Updated on 16-Jun-2020 11:42:02

193 Views

Function overloading occurs when a function performs different tasks based on a number of arguments passed to it.The best practice for function overloading with parameters is to not check the types. The code runs slower when the type is checked and it should be avoided. For this, the last parameter to the methods should be an objectAlso, do not check the argument length.ExampleHere’s an example −function display(a, b, value) { } display(30, 15, {"method":"subtract"}); display(70, 90, {"test":"equals", "val":"cost"});

How do I view events fired on an element in Chrome?

Fendadis John
Updated on 30-Jul-2019 22:30:22

13K+ Views

To view events fired on an element, follow the below steps in Google Chrome:Open Google Chrome and press F12 to open Dev Tools.Now go to Sources TabGo to Event Listener Breakpoints, on the right:Click on the events and interact with the target element.If the event will fire, then you will get a breakpoint in the debugger.

What is the usage of yield keyword in JavaScript?

usharani
Updated on 03-Oct-2019 07:08:09

141 Views

The yield keyword is used in JavaScript to pause and resume a generator function. The value of the expression is returned to the generator's caller.Here’s the syntax, where “exp” is the expression and the optional value is returned by “val”, which is passed to the generator's next() method.[val] = yield [exp];Here are the examples:function* displayRank () {    var selPlayers= [1, 2, 3, 4];    for (var a = 0; a < selPlayers.length; a++) {       yield selPlayers[i];    } }After defining a generator function, use it like the following.Here displayRank() is the generator function:var rank = displayRank(); ... Read More

What are immediate functions in JavaScript?

varun
Updated on 16-Jun-2020 06:18:43

274 Views

The immediate function executes as soon as it is defined. To understand the role of immediate function, let’s see the difference between a function and an immediate function −Here’s immediate function −(function() {    var str = "display"; }()); function display() {    // this returns undefined    alert(str); }Here’s a function −var str = "display"; function display() {    // This returns "display"    alert(str); }Let’s see another example of immediate functions −var name = 'Amit'; (function(sName) {    alert( 'Student name = ' + sName ); }(sName))

Advertisements