Javascript Articles

Page 501 of 534

How does JavaScript .prototype work?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 471 Views

In JavaScript, every function has a prototype property that serves as a template for creating objects. Understanding prototypes is essential for mastering JavaScript's object-oriented programming capabilities and inheritance patterns. What is a Prototype? A prototype is an object that exists on every function in JavaScript. When you create objects using constructor functions, they inherit properties and methods from the function's prototype. This enables code reusability and efficient memory usage. Consider creating multiple objects with similar properties: Basic Object Creation Creating Objects Without Prototype ...

Read More

How to turn a String into a JavaScript function call?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 571 Views

In JavaScript, you can dynamically call a function by converting a string containing the function name into an actual function call. This is useful when function names are determined at runtime. Using window Object (Browser) The most common method in browsers is using the window object to access globally defined functions: function myFunction(argument) { alert('My function ' + argument); } ...

Read More

Smart / self-overwriting / lazy getters in javaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 770 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. Smart or lazy getters are a special pattern where the getter replaces itself after the first computation, avoiding recalculation and improving performance. The getter helps when we need to get some dynamic value without an explicit call. Smart getters are particularly useful for expensive operations that should only run once. Syntax { get prop() {} } { get ...

Read More

How can I Execute JavaScript at the Command Prompt?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 13K+ Views

To execute JavaScript at the command prompt, you can use several methods depending on your environment. This article covers three practical approaches: running JavaScript files through Node.js, executing code directly in the Node.js REPL, and using the browser console for quick testing. In this article, we'll explore how to execute JavaScript at the command prompt using different methods. Methods to Run JavaScript at Command Line Here are three methods to execute JavaScript at the command prompt, each with detailed explanations and examples: Running JavaScript Files with Node.js ...

Read More

How to concatenate several strings in JavaScript?

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 322 Views

JavaScript provides multiple methods to concatenate several strings. The most common approaches include using the + operator, template literals, Array.join(), and the concat() method. Method 1: Using the + Operator The simplest way to concatenate strings is using the + operator: let str1 = "John"; let str2 = "Amit"; let str3 = "Sachin"; ...

Read More

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

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 372 Views

To fire a JavaScript function when the user finishes typing instead of on every keystroke, use a debouncing technique with setTimeout and clearTimeout. This prevents the function from executing until the user stops typing for a specified delay. The Problem Using keyup or input events directly fires a function on every keystroke, which can cause performance issues or unwanted API calls. Debouncing ensures the function only runs after the user has finished typing. Example with jQuery ...

Read More

What are the best practices for function overloading in JavaScript?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 315 Views

Function overloading occurs when a function performs different tasks based on the number or type of arguments passed to it. JavaScript doesn't support true function overloading like other languages, but we can implement similar behavior using best practices. Best Practices for Function Overloading When implementing function overloading in JavaScript, follow these key principles: Avoid type checking - Checking argument types slows down execution Don't check argument length - Use default parameters or options objects instead Use options objects - Pass configuration as the last parameter Leverage default parameters - Provide fallback values for missing arguments ...

Read More

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

Fendadis John
Fendadis John
Updated on 15-Mar-2026 16K+ Views

To view events fired on an element in Google Chrome, you can use the Developer Tools to monitor and debug event listeners. This is essential for understanding how user interactions trigger JavaScript functions on your webpage. Method 1: Using Event Listener Breakpoints Open Google Chrome and press F12 to open Developer Tools. Navigate to the Sources tab in the Developer Tools panel. Chrome Developer Tools - Sources Tab Sources Elements Console ...

Read More

What are immediate functions in JavaScript?

varun
varun
Updated on 15-Mar-2026 445 Views

Immediate functions in JavaScript are functions that execute automatically as soon as they are defined. They are also known as Immediately Invoked Function Expressions (IIFEs). These functions help create private scope and avoid polluting the global namespace. Syntax (function() { // Code here executes immediately })(); // Alternative syntax (function() { // Code here executes immediately }()); Basic Example (function() { var message = "Hello from IIFE!"; console.log(message); })(); // This variable is not ...

Read More

How to preserve variables in a JavaScript closure function?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 1K+ Views

In this tutorial, we will look at the method to preserve variables in a JavaScript closure function. What is a closure function? A closure function gives access to the scope of an outer function from an inner function. It also allows private variables. Closure variables are stored in stack and heap. When a function is created, closure is also created. Closure remembers external things used in it. Closures are the primary mechanism for data privacy. One drawback is that the variables used are not garbage collected. Overuse of closure functions will damage the system due to redundant ...

Read More
Showing 5001–5010 of 5,340 articles
« Prev 1 499 500 501 502 503 534 Next »
Advertisements