Writing Functions

Ok one of my biggest questions is why do programmers always write functions in javascript like:

function goldpen(laugh,blue) {

var laugh= 1;
var blue= 2;
}

What i wanted to know was do the brackets have to be written that way? Is it wrong if i wrote them:

function goldpen (laugh,blue) { var laugh= 1; var blue= 2; }

I was just wondering cuz it would save me alot of space to write it like that and it would make debugging easier.

Comments

  • First of all, yes, you are correct. You could write it all in one line without any later problems. However if you ever start writing larger scripts with more complex functions, writing it in one line would make the code look very messy and hard to follow. That is why programmers usually spread a block of data marked through { } over several lines. It makes the reading and following of the code much easier

    : Ok one of my biggest questions is why do programmers always write functions in javascript like:
    :
    : function goldpen(laugh,blue) {
    :
    : var laugh= 1;
    : var blue= 2;
    : }
    :
    : What i wanted to know was do the brackets have to be written that way? Is it wrong if i wrote them:
    :
    : function goldpen (laugh,blue) { var laugh= 1; var blue= 2; }
    :
    : I was just wondering cuz it would save me alot of space to write it like that and it would make debugging easier.
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion