Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 31 of 80

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 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 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 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 can I convert the arguments object to an array in JavaScript?

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

This tutorial teaches us to convert the arguments object to array in JavaScript. Before we proceed with the tutorial, let's look at the arguments object. In JavaScript, every function contains the 'arguments' object. It includes the values of all arguments we passed while calling or invoking the function. It is very similar to an array, but it is not an actual array. The 'arguments' object has a length property, and we can use it to know how many arguments are passed during the function call. ...

Read More

How do you get a timestamp in JavaScript?

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

In this tutorial, we will learn to get a timestamp in JavaScript. It never happens that software developers or application developers don't require to play with date and time. In many situations, they are required to play with date and timestamp. For example, to show the time on the user's dashboard, save the time of an operation in the database. Now, let's understand what the timestamp is? The timestamp is the total number of milliseconds from the 1st January 1970 from when UNIX epochs begin. Using the timestamp, we can extract the date, day, year, month, hours, minutes, second, ...

Read More

How do you reverse a string in place in JavaScript?

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

In this tutorial, we will learn to reverse a string in place in JavaScript. How to reverse a string is one of the most popular questions asked in the interview of freshers. It's an easy task but the interviewer can be tricky and make the same question difficult for you. For example, what if the interviewer asks you to write a pseudo code to reverse a string in place without using the extra space? You should have an answer ready in your mind for this kind of tricky question. There are lots of ways to reverse a string. As ...

Read More

How to load a JavaScript function using the variable name?

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

In JavaScript, there are several ways to load and execute functions using variable names. This technique is useful when you need to dynamically call functions or store function references in variables. Functions are blocks of reusable code that can be stored in variables and called later. JavaScript supports both named functions and anonymous functions, giving you flexibility in how you organize and execute your code. Anonymous Functions Anonymous functions are functions without a name. They must be assigned to a variable to be callable. This is the primary way to load a JavaScript function using a variable ...

Read More

What does the operator || do in a var statement in JavaScript?

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

In JavaScript, the logical OR operator (||) is commonly used in variable declarations to provide fallback or default values. When used with var, it returns the first "truthy" value or the last value if all are falsy. The logical OR operator evaluates operands from left to right and returns the first truthy value it encounters. If no truthy value is found, it returns the last operand. In JavaScript, falsy values include false, 0, "", null, undefined, and NaN. Syntax var result = expr1 || expr2; If expr1 is truthy, result will be expr1. Otherwise, ...

Read More

How to extract the hostname portion of a URL in JavaScript?

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

In this tutorial, we will see how to extract the hostname portion of a URL in JavaScript. What is a URL? A URL (Uniform Resource Locator) is a web address that identifies a specific resource on the internet. For example, tutorialspoint.com is a word-based URL. An IP address can also be used as a URL (ex. 192.168.2.24). Since names are simpler to recall than numbers, most users submit the name's address when searching on the internet. A URL is a method by which web browsers request specific pages from web servers. The syntax/format of a URL is ...

Read More
Showing 301–310 of 793 articles
« Prev 1 29 30 31 32 33 80 Next »
Advertisements