{"id":1471,"date":"2019-11-17T14:02:50","date_gmt":"2019-11-17T13:02:50","guid":{"rendered":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/?p=1471"},"modified":"2022-10-20T12:01:12","modified_gmt":"2022-10-20T10:01:12","slug":"12-javascript-tricks-you-not-there-ever-the-most-part-of-tutorial","status":"publish","type":"post","link":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/","title":{"rendered":"12 JavaScript tricks that you&#8217;ll never find in most tutorials"},"content":{"rendered":"\n<p class=\"has-medium-font-size wp-block-paragraph\">When I started to learn &nbsp;<a href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/grapesjs-web-builder\/\">Javascript<\/a>\u00a0, I made a list of all the tricks, useful for saving time, which I found in the code of other people, in the various web code sharing on programming sites, such as&nbsp;<a href=\"https:\/\/stackoverflow.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">stack overflow<\/a>&nbsp;at any&nbsp;&nbsp;<em>other<\/em>&nbsp;&nbsp;place&nbsp;&nbsp;<em>different from the<\/em>&nbsp;&nbsp;tutorial I was using.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Since then I have contributed to this list and, in this article, I will share 11 tips chosen at hand seem particularly intelligent or useful.&nbsp;This post is intended to be useful for the beginner, but I hope that the intermediate JavaScript developers will find something new in this list.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">While many of these tips are useful in any context, some may be better suited to the course code than the production-level code, where clarity is often more important than brevity;&nbsp;I&#8217;ll let you be the judge of that!<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">So, in no particular order, here are 11 ways to write code more concise and more efficient.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">In questo articolo:<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#1_Filter_unique_values\" >1. Filter unique values<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#2_Short_circuit_rating\" >2. Short circuit rating<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#3_Convert_to_Boolean\" >3. Convert to Boolean<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#4_Convert_to_string\" >4. Convert to string<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#5_Convert_to_Number\" >5. Convert to Number<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#6_rapid_Powers\" >6. rapid Powers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#7_Float_quick_on_whole\" >7. Float quick on whole<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#8_Automatic_Binding_in_classes\" >8. Automatic Binding in classes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#9_Truncate_a_matrix\" >9. Truncate a matrix<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#10_Get_the_last_elements_in_a_matrix\" >10. Get the last elements in a matrix<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#11_Format_the_JSON_code\" >11. Format the JSON code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#12_Length_of_the_cache_array_obsolete_in_loop\" >12. Length of the cache array [obsolete] in loop<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"e655\"><span class=\"ez-toc-section\" id=\"1_Filter_unique_values\"><\/span><strong>1. Filter unique values<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>ARRAYS<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;&nbsp;<code>Set<\/code>(object type) was introduced in ES6 and, together with&nbsp;&nbsp;<code>...<\/code>the operator &#8216;spread&#8217;, we can use it to create a new array with&nbsp;&nbsp;<em>only<\/em>&nbsp;&nbsp;unique values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const array = [1, 1, 2, 3, 5, 5, 1] \nconst uniqueArray = [... new set (array)]; console.log (uniqueArray); \n\/\/ Result: [1, 2, 3, 5]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Before ES6, isolate unique values \u200b\u200bwould mean a lot more code than that!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This trick works for arrays containing primitive types:&nbsp;&nbsp;<code>undefined<\/code>,&nbsp;&nbsp;<code>null<\/code>,&nbsp;&nbsp;<code>boolean<\/code>,&nbsp;&nbsp;<code>string<\/code>and&nbsp;&nbsp;<code>number<\/code>.&nbsp;(If you had an array of objects, additional functions or arrays, you&#8217;d need a different approach!)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"cbc0\"><span class=\"ez-toc-section\" id=\"2_Short_circuit_rating\"><\/span><strong>2. Short circuit rating<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>CONDITIONAL<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The ternary operator is a quick way to write simple conditional statements (and sometimes not so simple), like these:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">x&gt; 100? 'Above 100': 'Below 100'; \nx&gt; 100? (x&gt; 200? 'Above 200': 'Between 100-200'): 'Below 100';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But sometimes even the ternary operator is more complicated than necessary.&nbsp;Instead, we can use logical operators &#8216;AND&#8217;&nbsp;&nbsp;<code>&amp;&amp;<\/code> and &#8216;OR&#8217;&nbsp;&nbsp;<code>||<\/code>to evaluate certain expressions in a more concise way.&nbsp;This is often called &#8220;short&#8221; or &#8220;short circuit evaluation.&#8221;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"7644\">How does it work<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s say we want to return only one of two or more options.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">using&nbsp;&nbsp;<code>&amp;&amp;<\/code>&nbsp;return the first&nbsp;&nbsp;<code>false<\/code>&nbsp;or &#8220;false&#8221; If each operand value is evaluated&nbsp;&nbsp;<code>true<\/code>, it will be returned the last expression evaluated.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let one = 1, two = 2, 3 = three; \nconsole.log (one &amp;&amp; &amp;&amp; two three); \/\/ Result: 3 \nconsole.log (0 &amp;&amp; null); \/\/ Result: 0<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using&nbsp;&nbsp;<code>||<\/code>return the first&nbsp;&nbsp;<code>true<\/code>or &#8220;truth&#8221; value.&nbsp;If each operand is evaluated&nbsp;&nbsp;<code>false<\/code>, it will be returned the last expression evaluated.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let one = 1, two = 2, 3 = three; \nconsole.log (one two || || three); \/\/ Result: 1 \nconsole.log (0 || null); \/\/ Result: null<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"9467\">Example 1<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s say we want to return&nbsp;&nbsp;<code>length<\/code>to a variable, but do not know the type of variable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We could use&nbsp;&nbsp;<code>if\/else<\/code>an instruction to verify that&nbsp;&nbsp;<code>foo<\/code>it is an acceptable type but this could be quite forward-looking.&nbsp;The short circuit rating, we instead of doing this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> return (foo || []).length; <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the variable&nbsp;&nbsp;<code>foo<\/code>is true, it will be returned.&nbsp;Otherwise, the&nbsp;&nbsp;<code>length<\/code>array will be returned empty:&nbsp;&nbsp;<code>0<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"3e4f\">Example 2<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Have you ever had problems of access to a nested object property?&nbsp;You may not know if there is an object or sub-properties and this can cause frustrating errors.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose you want to access a property called&nbsp;&nbsp;<code>data<\/code>in&nbsp;&nbsp;<code>this.state<\/code>, but&nbsp;&nbsp;<code>data<\/code>is not defined until our program has not returned properly a retrieval request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Depending on where we use, the call&nbsp;&nbsp;<code>this.state.data<\/code>could prevent the execution of our app.&nbsp;To work around this, we could wrap it in a conditional:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if (this.state.data) { <br>  return this.state.data; <br>} Else { <br>  return 'Fetching Data'; <br>}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But it seems quite repetitive.&nbsp;The &#8216;or&#8217; operator provides a more concise solution:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> return (this.state.data || 'Fetching Data'); <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We can not refactificare the above code to use it&nbsp;&nbsp;<code>&amp;&amp;<\/code>.&nbsp;The declaration&nbsp;&nbsp;<code>'Fetching Data' &amp;&amp; this.state.data<\/code>will return&nbsp;&nbsp;<code>this.state.data<\/code>if it is&nbsp;&nbsp;<code>undefined<\/code>or not.&nbsp;This is because&nbsp;&nbsp;<code>'Fetching Data'<\/code>it is &#8220;true&#8221;, and then&nbsp;&nbsp;<code>&amp;&amp;<\/code>always pass when it is listed first.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"51c2\">A new proposed feature: the optional concatenation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">At the moment there is a proposal to allow &#8220;option chaining&#8221; when you try to return a property deep in a tree structure.&nbsp;Under the proposal, the question mark symbol&nbsp;&nbsp;<code>?<\/code>may be used to extract a property&nbsp;&nbsp;<em>only<\/em>&nbsp;&nbsp;if it is not&nbsp;&nbsp;<code>null<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, we could refactor our example above&nbsp;&nbsp;<code>this.state.data?.()<\/code>, thus returning only&nbsp;&nbsp;<code>data<\/code>if it is not&nbsp;&nbsp;<code>null<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Or, if we were mainly concerned that&nbsp;&nbsp;<code>state<\/code>was defined or not, we could go back&nbsp;&nbsp;<code>this.state?.data<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The proposal is currently in Phase 1, as an experimental feature.&nbsp;You can read it&nbsp;&nbsp;<a href=\"https:\/\/github.com\/tc39\/proposal-optional-chaining\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>&nbsp;&nbsp;, and you can use it in your JavaScript now through Babel, adding&nbsp;&nbsp;@ babel \/ plugin-proposal-optional-linking&nbsp;&nbsp;to your&nbsp;&nbsp;<code>.babelrc<\/code> files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6467\"><span class=\"ez-toc-section\" id=\"3_Convert_to_Boolean\"><\/span><strong>3. Convert to Boolean<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>CONVERSION OF TYPE<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition to standard Boolean values&nbsp;&nbsp;<code>true<\/code>and&nbsp;&nbsp;<code>false<\/code>, JavaScript also treats all other values as &#8220;truth&#8221; or &#8220;false&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Unless otherwise defined, all values are in JavaScript &#8216;truthy&#8217; with the exception of&nbsp;&nbsp;<code>0<\/code>,&nbsp;&nbsp;<code>\"\"<\/code>,&nbsp;&nbsp;<code>null<\/code>,&nbsp;&nbsp;<code>undefined<\/code>,&nbsp;&nbsp;<code>NaN<\/code>and, of course&nbsp;&nbsp;<code>false<\/code>, that they are &#8216;falsy&#8217;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can easily switch from true to false negative using the operator&nbsp;&nbsp;<code>!<\/code>, which also convert the type&nbsp;&nbsp;<code>\"boolean\"<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">IsTrue = const! 0; \nconst IsFalse =! 1; \nalsoFalse !! const = 0; \nconsole.log (IsTrue); \/\/ Result: true \nconsole.log (typeof true); \/\/ Result: \"boolean\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This kind of type conversion can be useful in conditional statements, even if the only reason you would choose to define&nbsp;&nbsp;<code>false<\/code>as&nbsp;&nbsp;<code>!1<\/code>it is if you were playing golf code!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fc4a\"><span class=\"ez-toc-section\" id=\"4_Convert_to_string\"><\/span><strong>4. Convert to string<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>CONVERSION OF TYPE<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To quickly convert a number to a string, we can use the concatenation operator&nbsp;&nbsp;<code>+<\/code>followed by an empty set of quotation marks&nbsp;&nbsp;<code>\"\"<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const val = 1 + \"\"; \nconsole.log (val); \/\/ Result: \"1\" \nconsole.log (typeof val); \/\/ Result: \"string\"<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"0591\"><span class=\"ez-toc-section\" id=\"5_Convert_to_Number\"><\/span><strong>5. Convert to Number<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>CONVERSION OF TYPE<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can quickly get to the contrary by using the addition operator&nbsp;&nbsp;<code>+<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let int = \"15\"; \nint = int +; console.log (int); \/\/ Result: 15 \nconsole.log (typeof int); Result: \"number\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This can also be used to convert Boolean in numbers, as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log (+ true); \/\/ Return: 1 \nconsole.log (+ false); \/\/ Return: 0<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There may be contexts in which&nbsp;&nbsp;<code>+<\/code>will be interpreted as the concatenation operator rather than the addition operator.&nbsp;When that happens (and you want to return an integer, not a floating) you can instead use two tilde:&nbsp;&nbsp;<code>~~<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A tilde, known as &#8220;operator bitwise NOT&#8221;, is an equivalent operator&nbsp;&nbsp;<code>-n \u2014 1<\/code>.&nbsp;So, for example,&nbsp;&nbsp;<code>~15<\/code>it is equal to&nbsp;&nbsp;<code>-16<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The use of two consecutive tilde effectively cancels the operation because&nbsp;&nbsp;<code>\u2014 ( \u2014 n \u2014 1) \u2014 1 = n + 1 \u2014 1 = n<\/code>.&nbsp;In other words, it is&nbsp;&nbsp;<code>~ \u2014 16<\/code>the same&nbsp;&nbsp;<code>15<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const int = ~~ \"15\"; \nconsole.log (int); \/\/ Result: 15 \nconsole.log (typeof int); Result: \"number\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Although she can not think of many cases of use, the bitwise operator can also be used on boolean values:&nbsp;&nbsp;<code>~true = -2<\/code>and&nbsp;&nbsp;<code>~false = -1<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ca42\"><span class=\"ez-toc-section\" id=\"6_rapid_Powers\"><\/span><strong>6. rapid Powers<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>OPERATIONS<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">From ES7, it was possible to use the exponent operator&nbsp;&nbsp;<code>**<\/code>as a shortcut to the powers, which is faster than writing&nbsp;&nbsp;<code>Math.pow(2, 3)<\/code>.&nbsp;This is a simple thing, but it makes the list because they have not been updated to include many tutorials this operator!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log (2 ** 3); \/\/ Result: 8<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This should not be confused with the&nbsp;&nbsp;<code>^<\/code>symbol, commonly used to represent exponents, but in JavaScript is the bitwise XOR operator.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before ES7, the shorthand existed only for powers with base 2, using the operator bitwise left shift&nbsp;&nbsp;<code>&lt;&lt;<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ The following expressions are equivalent: Math.pow (2, n); <br>&lt;&lt; 2 (n - 1); <br>2 ** n;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For example,&nbsp;&nbsp;<code>2 &lt;&lt; 3 = 16<\/code>it equals&nbsp;&nbsp;<code>2 ** 4 = 16<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"b6bf\"><span class=\"ez-toc-section\" id=\"7_Float_quick_on_whole\"><\/span><strong>7. Float quick on whole<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>TRANSACTIONS \/ TYPE OF CONVERSION<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to convert a float to an integer, you can use&nbsp;&nbsp;<code>Math.floor()<\/code>,&nbsp;&nbsp;<code>Math.ceil()<\/code>or&nbsp;&nbsp;<code>Math.round()<\/code>.&nbsp;But there is also a faster way to truncate a float to an integer using&nbsp;&nbsp;<code>|<\/code>the bitwise OR operator.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log (23.9 | 0); \/\/ Result: 23 <br>console.log (-23.9 | 0); \/\/ result: -23<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The behavior&nbsp;&nbsp;<code>|<\/code>varies depending on whether you are dealing with positive or negative numbers, so it&#8217;s best to use this shortcut if you&#8217;re sure.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If&nbsp;&nbsp;<code>n<\/code>it is positive,&nbsp;&nbsp;<code>n | 0<\/code>round down.&nbsp;If&nbsp;&nbsp;<code>n<\/code>it is negative, rounded up.&nbsp;To put it more accurately, this operation removes everything that follows the decimal point, a float on a truncating integer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can achieve the same effect by using rounding&nbsp;&nbsp;<code>~~<\/code>, as above, and in fact&nbsp;&nbsp;<em>any<\/em>&nbsp;&nbsp;bit bitwise would force a float to an integer.&nbsp;The reason that these particular operations work is that &#8211; when forced to a whole number &#8211; the value remains unchanged.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"d13c\">Remove final figures<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The bitwise OR operator can also be used to remove any number of digits from the end of an integer.&nbsp;This means that you do not need to use code like this to convert between types:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let str = \"1553\"; \nNumber (str.substring (0, str.length - 1));<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Instead, the bitwise operator allows us to write:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log (1553\/10 | 0) \/\/ Result: 155 <br>console.log (1553\/100 | 0) \/\/ Result: 15 <br>console.log (1553\/1000 | 0) \/\/ Result: 1<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"63e6\"><span class=\"ez-toc-section\" id=\"8_Automatic_Binding_in_classes\"><\/span><strong>8. Automatic Binding in classes<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>CLASSES<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can use the notation ES6 arrow in class methods and thus suggests a link.&nbsp;This often save several lines of code in our class constructor and we can happily say goodbye to repetitive expressions like!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>this.myMethod=this.myMethod.bind(<em>this<\/em>)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">React import, {} Component from React; \nExport default class App {extends Compononent \n   constructor (props) { \n      super (props); \n      this.state = {}; \n   } \n\n   MyMethod = () =&gt; { \n      \/\/ This method is implicitly bound! \n   } \n\n   Render () { \n    return ( \n      &lt;&gt; \n        &lt;div&gt; \n          {this.myMethod ()} \n        &lt;\/ div&gt; \n      &lt;\/&gt; \n    ) \n   } \n\n};<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6acc\"><span class=\"ez-toc-section\" id=\"9_Truncate_a_matrix\"><\/span><strong>9. Truncate a matrix<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>ARRAYS<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to remove values from the end of an array in a destructive way, there are faster alternatives than using&nbsp;&nbsp;<code>splice()<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, if you are familiar with the original size of the array, you can redefine its length property, as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; \narray.length = 4; \nconsole.log (array); \/\/ result: [0, 1, 2, 3]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is an especially concise solution.&nbsp;However, I found that the run-time&nbsp;&nbsp;<code>slice()<\/code>method is even faster.&nbsp;If speed is your primary goal, consider using something like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; \narray.slice array = (0, 4); \nconsole.log (array); \/\/ result: [0, 1, 2, 3]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"056a\"><span class=\"ez-toc-section\" id=\"10_Get_the_last_elements_in_a_matrix\"><\/span><strong>10. Get the last elements in a matrix<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>ARRAYS<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The array method&nbsp;&nbsp;<code>slice()<\/code>can take negative integers and, if provided, will take values from the end of the array instead of the beginning.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; \nconsole.log (array.slice (-1)); \/\/ result: [9] \nconsole.log (array.slice (-2)); \/\/ result: [8, 9] \nconsole.log (array.slice (-3)); \/\/ result: [7, 8, 9]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"820d\"><span class=\"ez-toc-section\" id=\"11_Format_the_JSON_code\"><\/span><strong>11. Format the JSON code<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>JSON<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, you may have used&nbsp;&nbsp;<code>JSON.stringify<\/code>before, but did you realize that it can also help you indent your JSON for you?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;&nbsp;<code>stringify()<\/code>method takes two optional parameters: a&nbsp;&nbsp;<code>replacer<\/code>function, which can be used to filter the JSON displayed, and a&nbsp;&nbsp;<code>space<\/code>value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;&nbsp;<code>space<\/code>value takes an integer for the desired number of spaces or a string (for example,&nbsp;&nbsp;<code>'\\t'<\/code>to insert the cards) and can make reading the retrieved JSON data much simpler.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log (JSON.stringify ({alpha: 'A', beta: 'B'}, null, '\\ t')); \n\/\/ result: \n\/\/ '{ \n\/\/ \"alpha\": A, \n\/\/ \"beta\": B \n\/\/}'<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Overall, I hope you have found these tips useful as when I discovered them for the first time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You have a few tricks JavaScript on your own?&nbsp;I&#8217;d love to read them in the comments below!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7944\"><span class=\"ez-toc-section\" id=\"12_Length_of_the_cache_array_obsolete_in_loop\"><\/span><strong>12. Length of the cache array [obsolete] in loop<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>LOOP<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the original version of this article, I shared a suggestion to store the length of the array in the cache&nbsp;&nbsp;<code>for<\/code>loop.&nbsp;However, if it is a read-only cycle, modern JavaScript engines are dealing with this at compile time.&nbsp;It is no longer necessary unless the array length does not change (and, if so, you probably want to be recalculated with each iteration anyway).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks to several developers who have stressed that.&nbsp;If you want to know more, take a look at&nbsp;&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/stackoverflow.com\/questions\/5752906\/is-reading-the-length-property-of-an-array-really-that-expensive-an-operation\" target=\"_blank\">this question on StackOverflow<\/a>&nbsp;&nbsp;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For those interested, there was a certain incentive to writing&nbsp;&nbsp;<code>for (let i = 0, len = array.length; i &lt; len; i++)<\/code>instead&nbsp;&nbsp;<code>for (let i = 0; i &lt; array.length; i++)<\/code>.&nbsp;This is no longer the case!<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"JavaScript Fundamentals: Best Practices\" width=\"800\" height=\"450\" src=\"https:\/\/www.youtube.com\/embed\/NibsUd_InPU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><figcaption><a href=\"https:\/\/youtu.be\/NibsUd_InPU\" target=\"_blank\" rel=\"noreferrer noopener\">Javascript fundamentals<\/a><\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>When I started to learn Javascript, I made a list of all the tricks, useful for saving time, which I found in the code of other people, in the various web code sharing on programming sites, such as stack overflow at any  other  place  different from the  tutorial I was using.<\/p>\n","protected":false},"author":1,"featured_media":1463,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[268,1059],"tags":[2837,2839,2841,2845,996,998],"class_list":["post-1471","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles-en","category-development","tag-new-en","tag-to-en","tag-tutorial-en","tag-web-en","tag-website-create-en","tag-website-free-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>12 javascript tricks that no one will ever tell you - Antonio Lamorgese<\/title>\n<meta name=\"description\" content=\"12 JavaScript tricks, useful for saving time, which I never found in any tutorial. Indispensable for an agile web development.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"12 JavaScript tricks that you&#039;ll never find in most tutorials\" \/>\n<meta property=\"og:description\" content=\"When I started to learn Javascript, I made a list of all the tricks, useful for saving time, which I found in the code of other people, in the various web code sharing on programming sites, such as stack overflow at any other place different from the tutorial I was using.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/\" \/>\n<meta property=\"og:site_name\" content=\"Antonio Lamorgese\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-17T13:02:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-20T10:01:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/11\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"449\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Antonio Lamorgese\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"12 JavaScript tricks that you&#039;ll never find in most tutorials\" \/>\n<meta name=\"twitter:description\" content=\"When I started to learn Javascript, I made a list of all the tricks, useful for saving time, which I found in the code of other people, in the various web code sharing on programming sites, such as stack overflow at any other place different from the tutorial I was using.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/11\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg\" \/>\n<meta name=\"twitter:creator\" content=\"@AntonioLamorge3\" \/>\n<meta name=\"twitter:site\" content=\"@AntonioLamorge3\" \/>\n<meta name=\"twitter:label1\" content=\"Scritto da\" \/>\n\t<meta name=\"twitter:data1\" content=\"Antonio Lamorgese\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo di lettura stimato\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/\"},\"author\":{\"name\":\"Antonio Lamorgese\",\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/#\\\/schema\\\/person\\\/264cf3af38edc93a3362a4c47ec5b2f0\"},\"headline\":\"12 JavaScript tricks that you&#8217;ll never find in most tutorials\",\"datePublished\":\"2019-11-17T13:02:50+00:00\",\"dateModified\":\"2022-10-20T10:01:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/\"},\"wordCount\":1801,\"publisher\":{\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/#\\\/schema\\\/person\\\/264cf3af38edc93a3362a4c47ec5b2f0\"},\"image\":{\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg\",\"keywords\":[\"new\",\"to\",\"tutorial\",\"web\",\"website create\",\"website free\"],\"articleSection\":[\"Blog Articles\",\"Development\"],\"inLanguage\":\"it-IT\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/\",\"url\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/\",\"name\":\"12 javascript tricks that no one will ever tell you - Antonio Lamorgese\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg\",\"datePublished\":\"2019-11-17T13:02:50+00:00\",\"dateModified\":\"2022-10-20T10:01:12+00:00\",\"description\":\"12 JavaScript tricks, useful for saving time, which I never found in any tutorial. Indispensable for an agile web development.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg\",\"contentUrl\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg\",\"width\":800,\"height\":449,\"caption\":\"trucchiJavaScriptchenontroveraimainellamaggiorpartedeitutorial\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Blog Articles\",\"item\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/en\\\/category\\\/articles-en\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"12 JavaScript tricks that you&#8217;ll never find in most tutorials\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/#website\",\"url\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/\",\"name\":\"Antonio Lamorgese\",\"description\":\"Il web e i suoi strumenti operativi\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/#\\\/schema\\\/person\\\/264cf3af38edc93a3362a4c47ec5b2f0\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"it-IT\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/#\\\/schema\\\/person\\\/264cf3af38edc93a3362a4c47ec5b2f0\",\"name\":\"Antonio Lamorgese\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/ChiSono.png\",\"url\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/ChiSono.png\",\"contentUrl\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/ChiSono.png\",\"width\":120,\"height\":130,\"caption\":\"Antonio Lamorgese\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/ChiSono.png\"},\"description\":\"Amministratore di rete e sviluppatore. Dopo anni di esperienza nel settore, ho ideato un sistema di gestione dati MYSQL in PHP senza scrivere una sola riga di codice.&nbsp;Scopri di pi\u00f9....\",\"sameAs\":[\"https:\\\/\\\/www.Phpcodewizard.it\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/antonio-lamorgese-660735190\\\/\",\"https:\\\/\\\/pinterest.it\\\/antoniolamorgese9711\\\/\",\"https:\\\/\\\/x.com\\\/AntonioLamorge3\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/antoniolamorgese\",\"https:\\\/\\\/tumblr.com\\\/blog\\\/phpcodewizard\"],\"url\":\"https:\\\/\\\/www.phpcodewizard.it\\\/antoniolamorgese\\\/author\\\/antonio-lamorgese\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"12 javascript tricks that no one will ever tell you - Antonio Lamorgese","description":"12 JavaScript tricks, useful for saving time, which I never found in any tutorial. Indispensable for an agile web development.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/","og_locale":"it_IT","og_type":"article","og_title":"12 JavaScript tricks that you'll never find in most tutorials","og_description":"When I started to learn Javascript, I made a list of all the tricks, useful for saving time, which I found in the code of other people, in the various web code sharing on programming sites, such as stack overflow at any other place different from the tutorial I was using.","og_url":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/","og_site_name":"Antonio Lamorgese","article_published_time":"2019-11-17T13:02:50+00:00","article_modified_time":"2022-10-20T10:01:12+00:00","og_image":[{"width":800,"height":449,"url":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/11\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg","type":"image\/jpeg"}],"author":"Antonio Lamorgese","twitter_card":"summary_large_image","twitter_title":"12 JavaScript tricks that you'll never find in most tutorials","twitter_description":"When I started to learn Javascript, I made a list of all the tricks, useful for saving time, which I found in the code of other people, in the various web code sharing on programming sites, such as stack overflow at any other place different from the tutorial I was using.","twitter_image":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/11\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg","twitter_creator":"@AntonioLamorge3","twitter_site":"@AntonioLamorge3","twitter_misc":{"Scritto da":"Antonio Lamorgese","Tempo di lettura stimato":"12 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#article","isPartOf":{"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/"},"author":{"name":"Antonio Lamorgese","@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/#\/schema\/person\/264cf3af38edc93a3362a4c47ec5b2f0"},"headline":"12 JavaScript tricks that you&#8217;ll never find in most tutorials","datePublished":"2019-11-17T13:02:50+00:00","dateModified":"2022-10-20T10:01:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/"},"wordCount":1801,"publisher":{"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/#\/schema\/person\/264cf3af38edc93a3362a4c47ec5b2f0"},"image":{"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#primaryimage"},"thumbnailUrl":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/11\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg","keywords":["new","to","tutorial","web","website create","website free"],"articleSection":["Blog Articles","Development"],"inLanguage":"it-IT"},{"@type":"WebPage","@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/","url":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/","name":"12 javascript tricks that no one will ever tell you - Antonio Lamorgese","isPartOf":{"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#primaryimage"},"image":{"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#primaryimage"},"thumbnailUrl":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/11\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg","datePublished":"2019-11-17T13:02:50+00:00","dateModified":"2022-10-20T10:01:12+00:00","description":"12 JavaScript tricks, useful for saving time, which I never found in any tutorial. Indispensable for an agile web development.","breadcrumb":{"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/"]}]},{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#primaryimage","url":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/11\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg","contentUrl":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/11\/12-trucchi-JavaScript-che-non-troverai-mai-nella-maggior-parte-dei-tutorial.jpg","width":800,"height":449,"caption":"trucchiJavaScriptchenontroveraimainellamaggiorpartedeitutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/12-javascript-tricks-that-youll-never-find-in-most-tutorials\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/"},{"@type":"ListItem","position":2,"name":"Blog Articles","item":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/en\/category\/articles-en\/"},{"@type":"ListItem","position":3,"name":"12 JavaScript tricks that you&#8217;ll never find in most tutorials"}]},{"@type":"WebSite","@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/#website","url":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/","name":"Antonio Lamorgese","description":"Il web e i suoi strumenti operativi","publisher":{"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/#\/schema\/person\/264cf3af38edc93a3362a4c47ec5b2f0"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"it-IT"},{"@type":["Person","Organization"],"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/#\/schema\/person\/264cf3af38edc93a3362a4c47ec5b2f0","name":"Antonio Lamorgese","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/06\/ChiSono.png","url":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/06\/ChiSono.png","contentUrl":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/06\/ChiSono.png","width":120,"height":130,"caption":"Antonio Lamorgese"},"logo":{"@id":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-content\/uploads\/2019\/06\/ChiSono.png"},"description":"Amministratore di rete e sviluppatore. Dopo anni di esperienza nel settore, ho ideato un sistema di gestione dati MYSQL in PHP senza scrivere una sola riga di codice.&nbsp;Scopri di pi\u00f9....","sameAs":["https:\/\/www.Phpcodewizard.it\/","https:\/\/www.linkedin.com\/in\/antonio-lamorgese-660735190\/","https:\/\/pinterest.it\/antoniolamorgese9711\/","https:\/\/x.com\/AntonioLamorge3","https:\/\/www.youtube.com\/user\/antoniolamorgese","https:\/\/tumblr.com\/blog\/phpcodewizard"],"url":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/author\/antonio-lamorgese\/"}]}},"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-json\/wp\/v2\/posts\/1471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-json\/wp\/v2\/comments?post=1471"}],"version-history":[{"count":0,"href":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-json\/wp\/v2\/posts\/1471\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-json\/wp\/v2\/media\/1463"}],"wp:attachment":[{"href":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-json\/wp\/v2\/media?parent=1471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-json\/wp\/v2\/categories?post=1471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpcodewizard.it\/antoniolamorgese\/wp-json\/wp\/v2\/tags?post=1471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}