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 316 of 534
Is it a good practice to end switch with defaults in JavaScript?
In this tutorial, we will learn if it is a good practice to end switch with defaults in JavaScript. In JavaScript, we generally use the if or if-else statements if we need to check any conditions. Still, if we need to check multiple conditions for an expression, it becomes very complex and unorganized, so we use the switch statements for that situation. The switch statement compares the value of an expression to a series of case clauses, then executes statements after the first case clause that matches the value, and so on, until a break statement is met. ...
Read MoreAre both addition and concatenation same in JavaScript?
In JavaScript, addition and concatenation are fundamentally different operations that can produce similar results depending on the data types involved. The + operator performs both operations contextually, while the concat() method is specifically for concatenation. The + operator behaves differently based on operand types: when at least one operand is a string, it performs concatenation; when both operands are numbers, it performs arithmetic addition. The concat() method, however, is only available for strings and arrays. String Operations For strings, both + operator and concat() method produce identical results. Using Addition (+) ...
Read MoreHow to get the value of the rel attribute of a link in JavaScript?
In this tutorial, we will learn how to get the value of the rel attribute of a link in JavaScript. The rel attribute expresses the relationship between the current document or website and the linked document or website. The search engine uses this attribute to get more information about the link, so it is important for the SEO of the website. The rel attribute can have different values like alternate, author, external, nofollow, etc.; each value means different information about the link. For example, 'alternate' means the link represents an alternate version of the current document. Using ...
Read MoreHow to perform numeric sort in JavaScript?
In JavaScript, the sort() method can be used to sort numeric arrays, but it requires a compare function for proper numeric ordering. Without it, numbers are sorted as strings, leading to unexpected results. The Problem with Default sort() When using sort() without a compare function, JavaScript converts numbers to strings and compares them lexicographically (alphabetically). This causes "10" to come before "2" because "1" comes before "2" in string comparison. let my_array = [61, 34, 54, 2, 12, 67, 89, ...
Read MoreConvert the string of any base to integer in JavaScript
The parseInt() function in JavaScript converts strings representing numbers in any base (2-36) to decimal integers. This is useful when working with binary, octal, hexadecimal, or other numeral systems. Syntax parseInt(string, radix); Parameters string − The value to parse. If not a string, it's converted using the ToString method. Leading whitespace is ignored. radix − An integer between 2 and 36 representing the base of the numeral system. If omitted, defaults to 10 (except for strings starting with "0x" which default to 16). Examples Converting Different Bases to Decimal ...
Read MoreHow to get the value of the type attribute of a link in JavaScript?
To get the value of the type attribute of a link in JavaScript, use the type property. The type attribute specifies the MIME type of the linked document, such as "text/html" for HTML documents or "text/css" for stylesheets. Syntax element.type Example: Getting Link Type Attribute You can access the type attribute of a link using getElementById() and the type property: TutorialsPoint var myVal = document.getElementById("anchorid").type; console.log("Value ...
Read MoreWhat is the difference between `new Object()` and object literal notation in JavaScript?
JavaScript provides two main ways to create objects: new Object() constructor and object literal notation {}. While both create objects, they have important differences in syntax, performance, and flexibility. Object Literal Notation Object literal notation uses curly braces {} to create objects directly with properties: let person = { name: 'Ayush', age: 25, city: 'Delhi' }; console.log(person.name); console.log(person); Ayush { name: 'Ayush', age: 25, city: 'Delhi' } Using new Object() Constructor The new Object() constructor creates an ...
Read MoreHow to work with document.anchors in JavaScript?
In this tutorial, let us discuss how to work with the document's anchor in JavaScript. The document.anchors property is a legacy feature that returns a collection of all anchor elements with a name attribute. While modern web development no longer recommends this property, some browsers still support it for compatibility reasons. The anchor tag represents hyperlinks and navigation points within a document. For document.anchors to include an anchor element, it must have a name attribute — elements with only href attributes are not included. Syntax let anchors = document.anchors; Properties length ...
Read MoreHow to work with document.body in JavaScript?
In this tutorial, we will learn how to work with document.body in JavaScript. The document.body property provides access to the HTML element, which contains all visible content of a web page including headings, paragraphs, images, hyperlinks, tables, and lists. In an HTML document, there can only be one element. In this tutorial, we will work with the document.body in JavaScript for: Change the background color of the body Add a new element at the end of the body Change the Background Color Using document.body ...
Read MoreWhat is JSlint error "missing radix parameter" in JavaScript?
The parseInt function in JavaScript has the following signature: parseInt(string, radix); Where the parameters are: string − The value to parse. If this argument is not a string, then it is converted to one using the ToString method. Leading whitespace in this argument is ignored. radix − An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the string. The Problem: Omitting the Radix Parameter If the radix parameter is omitted, JavaScript assumes the following: If the string begins ...
Read More