You can reduce the quality of photos to speed up the loading of your site
JavaScript is a complex language. If you are a JavaScript developer at any level, it is important to understand the basics. This article addresses 12 concepts that are important for any JS developer to understand, but by no means cover the full extent of what a JS developer needs to know.
NET 5., the successor to .NET Core 3.1. And .NET Framework 4.8., Intends to bring a new cross-platform development experience to .NET developers. Offer. This brings new good features. Of course, in this article you will not learn everything about .NET 5., but you can focus on 5 to get a better understanding of what is happening.
If you own a website or work on a customer website, then you need to know the importance of SEO. Without proper SEO strategies, you can not get high rankings in Google.
Success in a media channel such as organic search depends on the content. In particular, the production of useful content has the ability to rank. In its recent algorithm updates, Google has focused heavily on promoting great content and natural links, and penalizing poor content with unspecified links.
According to RedMonk, JavaScript is one of the most popular programming languages. This means that many developers use JavaScript.
1. Use shortcuts for conditions
JavaScript lets you use specific shortcuts to make your code easier. In some simple cases you can use the logical operators && and || Use instead of if and else.
Let's examine the && operator in action.
Example:
Operator || Acts as an "or" command. Now using this operator requires a bit of skill because it can prevent the program from running. However, we can add a condition to bypass it.
Example:
2. How to convert to the largest Integer using the operator (~~)
Using Math.floor to Return the Largest Integer (Integer), which in a statement is less than a definite number, takes resources, needless to say, is a relatively long string to keep in mind. A more efficient way is to use the (~~) operator.
An example is given here:
3. Resize or empty the array using array.length
Sometimes you have to adjust the size of your array or empty it. The most efficient way to do this is to use array.length.
Example:
You can also use array.length to remove all values from a specified array.
Example:
4. How to merge arrays without causing server overload
There may be serious pressure on the server when merging arrays, especially if you are dealing with a large data set. Use the Array.concat () and Array.push.apply (arr1, arr2) functions to keep things simple and maintain performance.
Using any of these functions depends on the size of your arrays.
Let's see how to deal with smaller arrays.
Example:
When using the Array.concat () function in a larger data set, it consumes a lot of memory while a new array is being created. To bypass the performance drop, use Array.push.apply (arr1, arr2), which merges the second array into the first array without creating a new one.
Example:
5. How to use filters with arrays
Filtering an array is useful when working with multiple relevant data columns. In this case, you can describe the data based on any attribute that describes a group in your array.
Use the filter () function to filter the array.
Example:
You can also use the filter () with Boolean to remove all null or undefined values from your array. Example:
6. How to extract unique values
Suppose you have a data set of duplicate values and you need to generate unique values from this set. You can do this with a combination of syntax ... and the Set object type. This approach works with both numbers and words.
Example:
7. How to use the Replace function
You should be familiar with the String.replace () function. However, it replaces a string with a specific line only once and stops from there. Suppose you have a larger data set and you have to write this function several times. It gets boring after a while.
To make it easier for you to operate, you can put / g at the end of the regex, so the function runs non-stop in the first place and replaces all match conditions.
Example:
8. How to drag values
When you work with large arrays and need to request elements with Id using getElementById (), or with a class name using getElementsByClassName (), JavaScript runs through the array in a loop with each request for the same element. This can take a lot of resources.
However, if you know you are using a specific selection on a regular basis, you can increase performance by swiping a certain amount.
Example:
9. Check if the object has value
When working with multiple objects, it is difficult to keep track of which ones have real values and which ones you can delete.
Here is a quick way to check if an object is empty or empty with the Object.keys () function.
Example:
10. How to shrink JavaScript files
Large JS files affect page load and response performance. When writing code, you can delete unnecessary lines, comments, and unused code.
There are tools to help you clean up code and make JS files lighter, or so-called minify their developers. Doing so is very beneficial for developers.
There are tools to help you clean up code and make JS files lighter, or so-called minify their developers. Doing so is very beneficial for developers.
Using these 10 items will help you build cleaner code, save server resources, and save programming time.
User:sinahabibi
2/1/2021
Visit:41
Java Script