5

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 ?

Mahendran
  • 468
  • 8
  • 19
  • possible duplicate of [var functionName = function() {} vs function functionName() {}](http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname) – Walter Chapilliquen - wZVanG Jun 25 '15 at 04:27
  • 2
    " Is it important ...?" No, it's not important. "will it influence page loading performance?" No, it won't. – Ram Jun 25 '15 at 04:27
  • @wZVanG no, that's not really what he's asking at all, actually. He never has any `var functionName = function(){}` in either of his code samples – markasoftware Jun 25 '15 at 04:27
  • i think my question is some what different , that question is speak about ways of declaring the function, it is different i think so. – Mahendran Jun 25 '15 at 04:30
  • possible duplicate of [JSLint: Using a function before it's defined error](http://stackoverflow.com/questions/806163/jslint-using-a-function-before-its-defined-error) – Paddy Jun 25 '15 at 04:35

1 Answers1

4

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

markasoftware
  • 12,292
  • 8
  • 41
  • 69
  • "It makes your code more readable and is considered good practise" and "it doesn't matter" seem contradictory to me :-P – Bergi Jun 25 '15 at 06:25