{"id":412,"date":"2025-07-08T17:08:56","date_gmt":"2025-07-08T07:08:56","guid":{"rendered":"https:\/\/nonlinearexperience.com\/?p=412"},"modified":"2025-07-08T17:08:56","modified_gmt":"2025-07-08T07:08:56","slug":"coding-best-practices","status":"publish","type":"post","link":"https:\/\/nonlinearexperience.com\/index.php\/2025\/07\/08\/coding-best-practices\/","title":{"rendered":"Coding best practices"},"content":{"rendered":"<h1 class=\"wp-block-post-title\">Coding best practices<\/h1>\n\n\n<p class=\"wp-block-paragraph\">See also:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">System:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">VARIABLES<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JS &#8211; when you want a changeable or mutable variable <strong>use a let<\/strong>. For any data that should be protected from accidentally being overwritten, like an object, or an array or a function, <strong>use a const<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">COMPARISON<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JS &#8211; use === for absolute equality<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FUNCTIONS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JS &#8211; use function expression &#8211; attached to a const &#8211; locally\/block scoped &#8211; best practice<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JS &#8211; anonymous functions using arrow functions &#8211; helps reduce memory usage<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">LOOPS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JS &#8211; use &#8216;foreach&#8217; for arrays &#8211; use &#8216;for\u2026in&#8217; for objects<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">EVENTS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JS &#8211; Pass arguments through event listeners &#8211; BEST OF ALL WORLDS EVENT LISTENERS<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">LOADING<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JS &lt;script src=&#8221;JS\/script.js&#8221; defer&gt;&lt;\/script&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use Modules to arrange code &gt; NOTE &#8211; if you set the type to &#8216;Module&#8217; they will automatically be deferred\u2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&lt;script type=&#8221;module&#8221; src=&#8221;backpack.js&#8221;&gt;&lt;\/script&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&lt;script type=&#8221;module&#8221; src=&#8221;script.js&#8221;&gt;&lt;\/script&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Caller-&gt; import objectName from &#8220;.\/objectName.js&#8221;;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Callee-&gt; export default objectName;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SCOPE &#8211; the Callee is scoped to the Caller, so not available from the browser console\u2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So therefore, it is better to use CLASSES (as templates) using this technique<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">* Class expression:&nbsp; const Name = class {}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The &#8216;expression&#8217; approach is currently the most favoured\u2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>See also: System: VARIABLES JS &#8211; when you want a changeable or mutable variable use a let. For any data that should be protected from accidentally being overwritten, like an object, or an array or a function, use a const. COMPARISON JS &#8211; use === for absolute equality FUNCTIONS JS &#8211; use function expression &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"wp-custom-template-nlx-the-knowledge-page","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-412","post","type-post","status-publish","format-standard","hentry","category-the-knowledge"],"_links":{"self":[{"href":"https:\/\/nonlinearexperience.com\/index.php\/wp-json\/wp\/v2\/posts\/412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nonlinearexperience.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nonlinearexperience.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nonlinearexperience.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nonlinearexperience.com\/index.php\/wp-json\/wp\/v2\/comments?post=412"}],"version-history":[{"count":1,"href":"https:\/\/nonlinearexperience.com\/index.php\/wp-json\/wp\/v2\/posts\/412\/revisions"}],"predecessor-version":[{"id":413,"href":"https:\/\/nonlinearexperience.com\/index.php\/wp-json\/wp\/v2\/posts\/412\/revisions\/413"}],"wp:attachment":[{"href":"https:\/\/nonlinearexperience.com\/index.php\/wp-json\/wp\/v2\/media?parent=412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nonlinearexperience.com\/index.php\/wp-json\/wp\/v2\/categories?post=412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nonlinearexperience.com\/index.php\/wp-json\/wp\/v2\/tags?post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}