Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it important to normalize local declaration in javascript

Tags:

javascript

I have installed the Resharper extension to visual studio.When i implement the code like below in JavaScript

updateTable();
function updateTable(){
//code here
}

it suggest me to normalise the local declaration,it will change code to like below

function updateTable(){
//code here
}

updateTable();

However both code snippet is work well , Is it important to normalize local declaration?. will it influence page loading performance ? Is it Standard to be followed ?

like image 479
Mahendran Avatar asked Sep 27 '22 12:09

Mahendran


1 Answers

No, it will not affect performance or do anything negatively. It can make your code look nicer, and I'm guessing that a lot of people consider it to be a good practice, but it does not affect the end result. Before running a script, the browser must download the whole script, regardless of where functions are defined, so it doesn't affect anything. However, note that if you ever use something like var thisIsAFunction=function(){...} instead of function ThisIsAFunction(){...}, you WILL need to put that first, otherwise you will get errors.

NL;DR: No, it doesn't matter

like image 137
markasoftware Avatar answered Oct 06 '22 18:10

markasoftware