<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Top 7 Javascript Best Practices For Beginners 👍]]></title><description><![CDATA[<p dir="auto"><img alt="alt text" class=" img-responsive img-markdown" /></p>
<hr />
<h3>1. Always use <strong>camelcase</strong> when declare variables.</h3>
<hr />
<p dir="auto"><strong>❌ Don't Use</strong></p>
<pre><code>var first_name = document.ElementById("firstname").value;
var date_of_birth = document.ElementById("dob").value;
</code></pre>
<p dir="auto"><strong>✔ Use</strong></p>
<pre><code>var firstName = document.ElementById("firstname").value;
var dateOfBirth = document.ElementById("dob").value;
</code></pre>
<hr />
<h3>2. Use <strong>shorten IF</strong> in small conditions.</h3>
<hr />
<p dir="auto"><strong>❌ Don't Use</strong></p>
<pre><code>//Un-Compressed Code
if ( age &lt; 19 ) {
      isMajor = false;
} else {
      isMajor = true;
}
</code></pre>
<p dir="auto"><strong>✔ Use</strong></p>
<pre><code>//Compressed Code
isMajor = ( age &lt; 19 ) ? false : true; 
</code></pre>
<hr />
<h3>3. Declare Variables <strong>outside</strong> of loop.</h3>
<hr />
<blockquote>
<p dir="auto">Not in all cases. Do it when you use common components/functions/DOMs inside the loop.</p>
</blockquote>
<p dir="auto"><strong>❌ Don't Use</strong></p>
<pre><code>for(var i = 0; i &lt; someArray.length; i++) {
   var container = document.getElementById('container');
   container.innerHtml += 'my number: ' + i;
}

/* 
This will load the DOM each time of the loop. 
Will slowdown your application performance in big cases.
*/
</code></pre>
<p dir="auto"><strong>✔ Use</strong></p>
<pre><code>var container = document.getElementById('container');

for(var i = 0; i &lt; someArray.length; i++) {
   container.innerHtml += 'my number: ' + i;
   console.log(i);
}
</code></pre>
<hr />
<h3>4. <strong>Reduce</strong> the single global variables.</h3>
<hr />
<p dir="auto"><strong>❌ Don't Use</strong></p>
<pre><code>var userId = '123456';
var userName = 'username';
var dateOfBirth = '06-11-1998';

function doSomething(userId,userName,dateOfBirth){
      //Your Implementation
}
</code></pre>
<p dir="auto"><strong>✔ Use</strong></p>
<pre><code>//Make a collection of data
var userData = {
   userId : '123456',
   userName : 'username',
   dateOfBirth : '06-11-1998'
}

function doSomething(userData){
      //Your Implementation
}

function doSomethingElse(userData.userId){
      //Your Implementation
}
</code></pre>
<hr />
<h3>5. Always <strong>comment</strong> your works &amp; function input,outputs.</h3>
<hr />
<p dir="auto"><strong>❌ Don't Use</strong></p>
<pre><code>function addNumbers(num1, num2){
     return num1 + num2;
}

function getDataById(id){
     return someDataArray[id];
}
</code></pre>
<p dir="auto"><strong>✔ Use</strong></p>
<pre><code>/*
* Adding two numbers
* @para num1 (int), num2 (int)
* @return int
*/
function addNumbers(num1, num2){
     return num1 + num2;
}

/*
* Adding two numbers
* @para id (int)
* @return Array
*/
function getDataById(id){
     return someDataArray[id];
}
</code></pre>
<hr />
<h3>6. Always <strong>Build/Minify</strong> your JS before move it to live.</h3>
<hr />
<p dir="auto">Commenting your works, New lines &amp; other best practices will <code>increase</code> your javascript file size. We need this stuffs in <strong>Development Environment</strong> only.</p>
<p dir="auto">So <strong>Build &amp; Minify</strong> your javascript file using build tools. It will compress your javascript to load much faster.</p>
<p dir="auto">Asserts Build Tool : <a href="https://webpack.js.org" target="_blank" rel="noopener noreferrer nofollow ugc">Webpack</a><br />
Online Javascript Minifier : <a href="https://javascript-minifier.com/" target="_blank" rel="noopener noreferrer nofollow ugc">javascript-minifier</a></p>
<hr />
<h3>7. Load your scripts just <strong>before &lt;/body&gt; Tags</strong>.</h3>
<hr />
<p dir="auto"><strong>❌ Don't Use</strong></p>
<pre><code>&lt;head&gt;
     &lt;!--Don't Load JS files here.--&gt;
&lt;/head&gt;
</code></pre>
<pre><code>&lt;body&gt;
      &lt;!--Don't Load JS files here.--&gt;
</code></pre>
<p dir="auto"><strong>✔ Use</strong></p>
<pre><code>          &lt;!--Load JS  files here.--&gt;
     &lt;/body&gt;
&lt;/html&gt;
</code></pre>
]]></description><link>https://lankadevelopers.lk/topic/151/top-7-javascript-best-practices-for-beginners</link><generator>RSS for Node</generator><lastBuildDate>Mon, 15 Jun 2026 20:54:19 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/151.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 19 Feb 2019 06:39:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Sat, 16 Mar 2019 07:48:26 GMT]]></title><description><![CDATA[<p dir="auto">Thank u bro</p>
]]></description><link>https://lankadevelopers.lk/post/1242</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1242</guid><dc:creator><![CDATA[imadusanka]]></dc:creator><pubDate>Sat, 16 Mar 2019 07:48:26 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Sat, 09 Mar 2019 16:44:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/800">@kapilsri</a> thx bro</p>
]]></description><link>https://lankadevelopers.lk/post/1215</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1215</guid><dc:creator><![CDATA[b6]]></dc:creator><pubDate>Sat, 09 Mar 2019 16:44:57 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Sat, 09 Mar 2019 16:44:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/274">@dee_kas</a> thx bro</p>
]]></description><link>https://lankadevelopers.lk/post/1214</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1214</guid><dc:creator><![CDATA[b6]]></dc:creator><pubDate>Sat, 09 Mar 2019 16:44:38 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Sat, 09 Mar 2019 16:44:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/129">@DevKasun</a> thx bro</p>
]]></description><link>https://lankadevelopers.lk/post/1213</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1213</guid><dc:creator><![CDATA[b6]]></dc:creator><pubDate>Sat, 09 Mar 2019 16:44:25 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Thu, 07 Mar 2019 14:31:27 GMT]]></title><description><![CDATA[<p dir="auto">really good thing</p>
]]></description><link>https://lankadevelopers.lk/post/1208</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1208</guid><dc:creator><![CDATA[kapilsri]]></dc:creator><pubDate>Thu, 07 Mar 2019 14:31:27 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Sat, 02 Mar 2019 08:22:26 GMT]]></title><description><![CDATA[<p dir="auto">Nice work.really useful</p>
]]></description><link>https://lankadevelopers.lk/post/1150</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1150</guid><dc:creator><![CDATA[dee_kas]]></dc:creator><pubDate>Sat, 02 Mar 2019 08:22:26 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Fri, 01 Mar 2019 05:22:09 GMT]]></title><description><![CDATA[<p dir="auto">useful article</p>
]]></description><link>https://lankadevelopers.lk/post/1138</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1138</guid><dc:creator><![CDATA[DevKasun]]></dc:creator><pubDate>Fri, 01 Mar 2019 05:22:09 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Sun, 24 Feb 2019 04:31:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/130">@lkdev</a> 😊😊😊</p>
]]></description><link>https://lankadevelopers.lk/post/1091</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1091</guid><dc:creator><![CDATA[b6]]></dc:creator><pubDate>Sun, 24 Feb 2019 04:31:22 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Sat, 23 Feb 2019 13:11:23 GMT]]></title><description><![CDATA[<p dir="auto">wow, nice looking post with very useful content, thanks <a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/625">@b6</a></p>
]]></description><link>https://lankadevelopers.lk/post/1084</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1084</guid><dc:creator><![CDATA[lkdev]]></dc:creator><pubDate>Sat, 23 Feb 2019 13:11:23 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Fri, 22 Feb 2019 12:35:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/625">@b6</a>  niceee</p>
]]></description><link>https://lankadevelopers.lk/post/1038</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1038</guid><dc:creator><![CDATA[tnlthanzeel]]></dc:creator><pubDate>Fri, 22 Feb 2019 12:35:50 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Wed, 20 Feb 2019 16:52:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/650">@tnlthanzeel</a> yep.. the assets <a href="http://will.be" target="_blank" rel="noopener noreferrer nofollow ugc">will.be</a> loaded quickly before javascript. So the site renders before, functions loads after</p>
]]></description><link>https://lankadevelopers.lk/post/1006</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1006</guid><dc:creator><![CDATA[b6]]></dc:creator><pubDate>Wed, 20 Feb 2019 16:52:29 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Wed, 20 Feb 2019 03:04:56 GMT]]></title><description><![CDATA[<p dir="auto">isnt it better to load the javascripts  just before closing the body tag? so the page will render faster</p>
]]></description><link>https://lankadevelopers.lk/post/998</link><guid isPermaLink="true">https://lankadevelopers.lk/post/998</guid><dc:creator><![CDATA[tnlthanzeel]]></dc:creator><pubDate>Wed, 20 Feb 2019 03:04:56 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Tue, 19 Feb 2019 16:37:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/2">@dev_lak</a> thx bro</p>
]]></description><link>https://lankadevelopers.lk/post/995</link><guid isPermaLink="true">https://lankadevelopers.lk/post/995</guid><dc:creator><![CDATA[b6]]></dc:creator><pubDate>Tue, 19 Feb 2019 16:37:41 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Tue, 19 Feb 2019 16:37:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/542">@GeethOnion</a> Thx bro</p>
]]></description><link>https://lankadevelopers.lk/post/994</link><guid isPermaLink="true">https://lankadevelopers.lk/post/994</guid><dc:creator><![CDATA[b6]]></dc:creator><pubDate>Tue, 19 Feb 2019 16:37:22 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Tue, 19 Feb 2019 16:37:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/348">@devR</a> Thx bro</p>
]]></description><link>https://lankadevelopers.lk/post/993</link><guid isPermaLink="true">https://lankadevelopers.lk/post/993</guid><dc:creator><![CDATA[b6]]></dc:creator><pubDate>Tue, 19 Feb 2019 16:37:10 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Tue, 19 Feb 2019 12:51:18 GMT]]></title><description><![CDATA[<p dir="auto">Nice post bro</p>
]]></description><link>https://lankadevelopers.lk/post/991</link><guid isPermaLink="true">https://lankadevelopers.lk/post/991</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Tue, 19 Feb 2019 12:51:18 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Tue, 19 Feb 2019 12:09:11 GMT]]></title><description><![CDATA[<p dir="auto">Very useful 😍</p>
]]></description><link>https://lankadevelopers.lk/post/990</link><guid isPermaLink="true">https://lankadevelopers.lk/post/990</guid><dc:creator><![CDATA[GeethOnion]]></dc:creator><pubDate>Tue, 19 Feb 2019 12:09:11 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Tue, 19 Feb 2019 11:38:48 GMT]]></title><description><![CDATA[<p dir="auto">useful post <a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/625">@b6</a></p>
]]></description><link>https://lankadevelopers.lk/post/989</link><guid isPermaLink="true">https://lankadevelopers.lk/post/989</guid><dc:creator><![CDATA[devR]]></dc:creator><pubDate>Tue, 19 Feb 2019 11:38:48 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Tue, 19 Feb 2019 11:12:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/27">@root</a> thx bro</p>
]]></description><link>https://lankadevelopers.lk/post/988</link><guid isPermaLink="true">https://lankadevelopers.lk/post/988</guid><dc:creator><![CDATA[b6]]></dc:creator><pubDate>Tue, 19 Feb 2019 11:12:21 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Tue, 19 Feb 2019 11:12:04 GMT]]></title><description><![CDATA[<p dir="auto">@Malith 👌👌</p>
]]></description><link>https://lankadevelopers.lk/post/987</link><guid isPermaLink="true">https://lankadevelopers.lk/post/987</guid><dc:creator><![CDATA[b6]]></dc:creator><pubDate>Tue, 19 Feb 2019 11:12:04 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Tue, 19 Feb 2019 08:10:46 GMT]]></title><description><![CDATA[<p dir="auto">Nice post bro.</p>
]]></description><link>https://lankadevelopers.lk/post/983</link><guid isPermaLink="true">https://lankadevelopers.lk/post/983</guid><dc:creator><![CDATA[root]]></dc:creator><pubDate>Tue, 19 Feb 2019 08:10:46 GMT</pubDate></item><item><title><![CDATA[Reply to Top 7 Javascript Best Practices For Beginners 👍 on Tue, 19 Feb 2019 07:10:47 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Bro</p>
]]></description><link>https://lankadevelopers.lk/post/980</link><guid isPermaLink="true">https://lankadevelopers.lk/post/980</guid><dc:creator><![CDATA[Nubelle]]></dc:creator><pubDate>Tue, 19 Feb 2019 07:10:47 GMT</pubDate></item></channel></rss>