Rishi Rathor

Rishi Rathor

99 Articles Published

Articles by Rishi Rathor

Page 3 of 10

What is the difference between new operator and object() constructor in JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 1K+ Views

Both the new operator and Object() constructor are used to create objects in JavaScript, but they serve different purposes and contexts. The new Operator The new operator is used to create an instance of an object. It works with constructor functions to instantiate objects and automatically handles the object creation process. var department = new Object(); var books = new Array("C++", "Perl", "Java"); var day = new Date("December 1, 2017"); document.write("Department: " + typeof department + ""); document.write("Books: " + books + ""); document.write("Date: " + day + ""); ...

Read More

How to list down all the cookies by name using JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 313 Views

To list all cookies by name in JavaScript, you access the document.cookie property, split it into individual cookie pairs, and extract the name-value pairs from each cookie. How document.cookie Works The document.cookie property returns all cookies as a single string, with each cookie separated by semicolons. For example: "name1=value1; name2=value2; name3=value3". Method 1: Basic Cookie Listing Here's a simple approach to list all cookies by splitting the cookie string: function ReadCookie() { ...

Read More

What is the shortest function of reading a cookie by name in JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 173 Views

The shortest way to read a cookie by name in JavaScript is using a one-line function that searches through document.cookie and extracts the specific value. Shortest Cookie Reader Function Here's the most concise function to read a cookie by name: Cookie Reader // Set some cookies first for testing document.cookie = "username=john; path=/"; document.cookie = "theme=dark; path=/"; ...

Read More

How to create cookies in JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 881 Views

Using cookies is the most efficient method of remembering and tracking preferences, purchases, commissions, and other information required for better visitor experience or site statistics. The simplest way to create a cookie is to assign a string value to the document.cookie object, which looks like this: document.cookie = "key1=value1;key2=value2;expires=date"; Here the expires attribute is optional. If you provide this attribute with a valid date or time, then the cookie will expire on a given date or time and thereafter, the cookies' value will not be accessible. Note − Cookie values may not include semicolons, ...

Read More

Why are parenthesis used to wrap a JavaScript function call?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 5K+ Views

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 More

How to provide new line in JavaScript alert box?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 808 Views

To add a new line in JavaScript alert box, use the "" escape character: Syntax alert("First lineSecond line"); Basic Example function showAlert() { alert("This is line oneThis is line twoThis is line three"); } Click to Show Alert Multiple Line Breaks You ...

Read More

What is the (function() { } )() construct in JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 2K+ Views

The (function() { } )() construct is an immediately invoked function expression (IIFE). It is a function that executes immediately upon creation, without needing to be called separately. Syntax (function() { // code })(); The first pair of parentheses converts the function declaration into an expression: (function(){...}) The second pair of parentheses immediately invokes that function expression. Basic Example (function() { console.log("IIFE executed immediately!"); })(); console.log("This runs after IIFE"); IIFE executed immediately! This runs after IIFE ...

Read More

What does the exclamation mark do before the function in JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 3K+ Views

The exclamation mark (!) before a function in JavaScript is used to create an Immediately Invoked Function Expression (IIFE). It transforms a function declaration into an expression that can be executed immediately. How It Works The ! operator has lower precedence than the parentheses (), so the function executes first, then the ! operator applies to its return value: !function() { console.log("IIFE executed!"); }(); IIFE executed! Return Value Behavior Since functions return undefined by default, the ! operator converts this to true: let result1 ...

Read More

Role of CSS justify-content property center value

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 270 Views

The CSS justify-content property with the center value is used to align flex items to the center of the main axis in a flex container. This creates equal spacing on both sides of the flex items, centering them horizontally within their container. Syntax .container { display: flex; justify-content: center; } Example The following example demonstrates how to center flex items using justify-content: center − .mycontainer { ...

Read More

Role of CSS justify-content property space-around value

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 178 Views

The CSS justify-content property with the space-around value distributes flex items evenly along the main axis with equal space around each item. This creates equal spacing on both sides of each item, making the space between adjacent items twice as large as the space at the edges. Syntax .container { display: flex; justify-content: space-around; } Example You can try to run the following code to implement the space-around value − ...

Read More
Showing 21–30 of 99 articles
« Prev 1 2 3 4 5 10 Next »
Advertisements