Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 502 of 534
Why are parenthesis used to wrap a JavaScript function call?
In JavaScript, functions wrapped with parentheses are called "Immediately Invoked Function Expressions" or "Self Executing Functions". The purpose of wrapping is to namespace and control the visibility of member functions. It wraps code inside a function scope and decreases clashing with other libraries. This is what we call Immediately Invoked Function Expression (IIFE) or Self Executing Anonymous Function. Syntax (function() { // code })(); As you can see above, the first pair of parentheses converts the code inside into an expression: (function(){...}) The second pair of parentheses ...
Read MoreWhat is the difference between closure and nested functions in JavaScript?
In JavaScript, closures and nested functions are related but distinct concepts. A closure occurs when an inner function retains access to variables from its outer function's scope, even after the outer function has finished executing. Nested functions are simply functions defined inside other functions. JavaScript Closures A closure is formed when a function "closes over" variables from its lexical scope. The inner function remembers the environment in which it was created, not where it's called. JavaScript Closures JavaScript Closures Example ...
Read MoreHow to change font size in HTML?
To change the font size in HTML, use the CSS font-size property. You can apply it using the style attribute for inline styles, internal CSS with the tag, or external CSS files. HTML5 does not support the deprecated tag, so CSS is the modern approach. Keep in mind that inline styles using the style attribute override any global styles set in tags or external stylesheets. Using Inline Styles The simplest method is using the style attribute directly on HTML elements: ...
Read MoreHow to create a link to send email with a subject in HTML?
To create a link that opens the user's email client with a pre-filled subject line, use the tag with a mailto: URL in the href attribute. Syntax Link Text Key Points Use mailto: followed by the recipient's email address Add ?Subject= to include a subject line Replace spaces in the subject with %20 (URL encoding) The link will open the user's default email client Basic Example ...
Read MoreUnderstanding function scope and context in JavaScript?
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 MoreHow to arguments object with Rest, default, and destructured parameters in JavaScript?
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 MoreHow to concatenate multiple string variables in JavaScript?
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 MoreHow to create a dialog with "yes" and "no" options in JavaScript?
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 MoreHow to change button label in alert box using JavaScript?
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 MoreHow to call a JavaScript function from C++?
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