Javascript Articles - Page 584 of 671

How to get the value of the target attribute of a link in JavaScript?

Shubham Vora
Updated on 15-Sep-2022 11:48:20

7K+ Views

In this tutorial, we will learn how to get the value of the target attribute of a link in JavaScript. The target attribute specifies where to open the linked document or page. By default, its value is set to ‘_self, ’ which means the linked document should open in the same window or tab. It can also have values like ‘_blank, ’ ‘_self, ’ ‘_parent, ’ ‘_top, ’ and ‘frame_name’, where each value defines a different location to open the linked document. Using the target property To get the value of the target attribute of a link in JavaScript, use ... Read More

What are the rules to be followed for Object Definitions in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 11:18:39

398 Views

In this tutorial, we will discuss the rules to follow for Object Definitions in JavaScript. JavaScript is an object-oriented scripting language. An object contains many properties. The property consists of a key and a value. The property is known as a method when this value is a function. Predefined objects are available in the browser. We can also define our objects. A real-life example of an object is a cup. The color, design, weight, and material are the main properties of a cup. The object name and the property name are case-sensitive. To define a property, we need to assign ... Read More

How to perform numeric sort in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 13:39:30

12K+ Views

In this tutorial, we will learn how to perform the numeric Sort in JavaScript. We can arrange the given numerical values by numerical sorting into ascending or descending order In JavaScript, we use the sort () method to sort numerical values. This method sorts the arrays of numbers, strings, and objects. It sorts the elements of an array and changes the order of the original array's elements. The array elements are cast to strings to determine the order and then compared and sorted. arr.sort() Where arr is the array of numeric elements that need to be sorted, this method ... Read More

How to get the value of the rel attribute of a link in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 09:15:29

3K+ Views

In this tutorial, we will learn how to get the value of the rel attribute of a link in JavaScript. The rel attribute expressed 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 document.getElementById() Method In ... Read More

How to improve the performance of JavaScript?

Shubham Vora
Updated on 15-Sep-2022 12:13:02

406 Views

In today's world, almost every website uses JavaScript. Web applications are becoming more complex and more user-interactive, and this has caused performance issues. It results in a poor user experience, which is not desirable for any web application. Different factors cause poor performance, long loading times, and long response times. In this tutorial, we will discuss all of these factors and how to resolve this issue and improve the performance of JavaScript. Light and Compact Code The first thing to improve the performance of JavaScript is to write light and compact code. The JavaScript code can have multiple modules and ... Read More

What will happen if a semicolon is misplaced in JavaScript?

Srinivas Gorla
Updated on 20-May-2020 09:04:03

221 Views

If a semicolon is misplaced in JavaScript, then it may lead to misleading results. Let’s see an example, wherein the if statement condition is false, but due to misplaced semi-colon, the value gets printed.Example                    var val1 = 10;          if (val1 == 15) {             document.write("Prints due to misplaced semi-colon: "+val1);          }          var val2 = 10;          if (val2 == 15) {             // this won't get printed             document.write(val2);          }          

Are both addition and concatenation same in JavaScript?

Sravani Alamanda
Updated on 08-Dec-2022 08:43:53

2K+ Views

We can't say whether both are the same or both are different. In some cases, addition and concatenation will have the same result, but in some cases, they will be different. It is completely based on the type of variables. We will see it in detail below We use the + operator for addition and the concat() method for concatenation in JavaScript. In some cases, both the + operator and the concat() method returns the same result. Adding and concatenating two strings using the + operator and the concat() method returns the same result. We can also apply the ... Read More

Is it a good practice to end switch with defaults in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 11:54:20

880 Views

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. If no ... Read More

Is it a good practice to place all declarations at the top in JavaScript?

Ayyan
Updated on 20-May-2020 09:07:11

133 Views

Yes, it is a good practice to place all the JavaScript declarations at the top. Let’s see an example −Example           JavaScript String match() Method                        // all the variables declared at top          var str, re, found;                    str = "For more information, see Chapter 3.4.5.1";          re = /(chapter \d+(\.\d)*)/i;          found = str.match( re );          document.write(found );           The following are the valid reasons −Gives a single place to check for all the variables.Helps in avoiding global variablesRe-declarations are avoided.The code is easy to read for others as well.

How to match a regular expression against a string?

Nancy Den
Updated on 23-Jun-2020 08:51:16

338 Views

Use the match() method to match a regular expression against a string in JavaScript. You can try to run the following code to match a regular expression −The following is the parameter −match( param ) − A regular expression object.ExampleYou can try to run the following code to match a regular expression against a string −           JavaScript String match() Method                        var str = "For more information, see Chapter 3.4.5.1";          var re = /(chapter \d+(\.\d)*)/i;          var found = str.match( re );                    document.write(found );          

Advertisements