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
Articles by Rishi Rathor
Page 3 of 10
What is the difference between new operator and object() constructor in JavaScript?
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 MoreHow to list down all the cookies by name using JavaScript?
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 MoreWhat is the shortest function of reading a cookie by name in JavaScript?
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 MoreHow to create cookies in JavaScript?
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 MoreWhy 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 MoreHow to provide new line in JavaScript alert box?
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 MoreWhat is the (function() { } )() construct in JavaScript?
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 MoreWhat does the exclamation mark do before the function in JavaScript?
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 MoreRole of CSS justify-content property center value
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 MoreRole of CSS justify-content property space-around value
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