Articles on Trending Technologies

Technical articles with clear explanations and examples

Understanding function scope and context in JavaScript?

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

In this tutorial, let us discuss the function scope and context in JavaScript. Functions are the building blocks of JavaScript. Understanding scope and context is crucial for writing maintainable code and avoiding common pitfalls. Scope Scope determines where variables can be accessed in your code. JavaScript has four types of scope: Global Scope Variables declared outside any function have global scope and are accessible throughout the program. Variables declared with var become properties of the window object, while let and const don't. Global Scope Example ...

Read More

How to arguments object with Rest, default, and destructured parameters in JavaScript?

Abhinaya
Abhinaya
Updated on 15-Mar-2026 240 Views

JavaScript ES6 introduced powerful parameter features that modernize how functions handle arguments. This article explores default parameters, rest parameters, and destructuring assignment - three essential concepts for writing cleaner, more flexible JavaScript functions. Default Parameters Default parameters allow you to initialize function parameters with default values when no value or undefined is passed. This eliminates the need for manual parameter checking and makes functions more robust. Syntax function functionName(param1, param2 = defaultValue) { // function body } Example ...

Read More

How to concatenate multiple string variables in JavaScript?

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

In this tutorial, we will learn to concatenate multiple string variables in JavaScript. String concatenation is the process of merging two or more strings into a single string. This operation is fundamental in JavaScript development and is commonly used for creating dynamic content, building messages, and manipulating text data. String concatenation is particularly useful when you need to insert substrings into existing strings or build complex strings from multiple variables. For example, when developing applications, you might need to combine user input with predefined text or merge data from different sources. There are three main methods to concatenate ...

Read More

How to create a dialog with "yes" and "no" options in JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 3K+ Views

JavaScript's built-in confirm() dialog only provides "OK" and "Cancel" buttons. To create a custom dialog with "Yes" and "No" options, you need to build a custom modal using HTML, CSS, and JavaScript. Built-in confirm() Limitation The standard confirm() function cannot be customized to show "Yes/No" buttons: // Built-in confirm() only shows OK/Cancel let result = confirm("Do you want to continue?"); console.log(result ? "User clicked OK" : "User clicked Cancel"); Custom Yes/No Dialog Solution Here's a complete custom dialog implementation using jQuery: ...

Read More

How to change button label in alert box using JavaScript?

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

In this tutorial, we will learn to change the button label in the alert box using JavaScript. The default JavaScript alert box contains a simple message and an "OK" button, but we cannot customize its appearance or button text directly. Since the native alert() method doesn't allow customization, we need to create custom alert boxes using HTML, CSS, and JavaScript. This approach gives us full control over styling and button labels. The Problem with Default Alert Boxes The default alert() method has limitations: ...

Read More

How to call a JavaScript function from C++?

Akansha Kumari
Akansha Kumari
Updated on 15-Mar-2026 1K+ Views

Calling a JavaScript function directly from C++ depends on the environment and the system; for this, make sure you have embedded a JavaScript engine or integrated C++ with JavaScript. In this article, we will be using Emscripten (C++ to JavaScript in WebAssembly) to call a JavaScript function from C++. For this, you have to compile the C++ program to WebAssembly using Emscripten and then call JavaScript functions from C++. So, first, create the C++ file with the header . How Emscripten Works Emscripten compiles C++ code to WebAssembly, which runs in browsers. The compiled WebAssembly module can ...

Read More

How to trigger event in JavaScript?

Vikal Singh
Vikal Singh
Updated on 15-Mar-2026 930 Views

In JavaScript, triggering events programmatically allows you to execute event handlers without user interaction. There are several methods to accomplish this, both in vanilla JavaScript and jQuery. Using jQuery trigger() Method jQuery's trigger() method fires the specified event and executes its default behavior for selected elements. Click Me // Attach event handler $("#myButton").on("click", function() { console.log("Button clicked: " + $(this).text()); }); // Trigger the click event programmatically $("#myButton").trigger("click"); Button clicked: Click Me Using Vanilla JavaScript dispatchEvent() Modern JavaScript provides the dispatchEvent() method ...

Read More

How to write a global error handler in JavaScript?

mkotla
mkotla
Updated on 15-Mar-2026 2K+ Views

Global error handlers in JavaScript allow you to catch unhandled exceptions and errors that occur anywhere in your application. This is essential for debugging and providing better user experience. Using window.onerror The window.onerror event handler catches JavaScript runtime errors, including syntax errors and uncaught exceptions. Syntax window.onerror = function(message, source, lineno, colno, error) { // Handle the error return true; // Prevents default browser error handling }; Parameters Parameter Description message Error message source URL of the script ...

Read More

How to center a popup window on screen using JavaScript?

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

In this tutorial, we will learn to center a popup window on the screen using JavaScript. Programmers often need to open a new popup window to show another webpage without redirecting the user to the other webpage. In this situation, developers use the window.open() method to open the new browser window. Also, we can style the popup window and set the height and width. Also, we can change the position of the popup window to look it better. Sample Popup Window In this section, we will create a sample popup window to get familiar with the how ...

Read More

How to call a JavaScript Function from Chrome Console?

Sreemaha
Sreemaha
Updated on 15-Mar-2026 2K+ Views

You can call JavaScript functions directly from the Chrome Developer Console. This is useful for testing, debugging, and interacting with functions defined in your web page or application. Opening Chrome Developer Console To access the console, press F12 or Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (Mac), then click the Console tab. Calling Functions from Console Once a function is defined in your page's JavaScript, you can call it directly from the console by typing the function name followed by parentheses. ...

Read More
Showing 19011–19020 of 61,297 articles
Advertisements