When should I use ;


#1

When should I use ;
And is it important


#2

Super important! You need to use ; after a lot of things.

console.log( 'your text' );

var varName = function (parameters) {
code
};

if (parameter) {
code
};

There is more than that on JavaScript, but this is the basic. And remember: using ; after your code is very important.


#3

Use the semicolon when you declare a variable and when you directly tell computer to do something right now.
For instance, there are two ways to create a function:

// 1
var func = function() {
    // code
};
// 2
function func() {
    // code
}

The first one directly orders computer to assign this function to the "func" variable, so we must put semicolon at the end. The second just tells computer: "There's such a function with a particular name and code", so no semicolon here.

When we call a function, we directly command computer to execute its code, so we need a semicolon.

func(); // Computer, execute the "func" function!

Another good example is the "if / else" statement.

if (condition1) {
    console.log("Hi!");
} else {
    console.log("Bye!");
}

This statement just makes computer understand what code to execute, so the semicolon isn't needed. When it understands, it starts executing specific direct commands which need the semicolon after them.

That's the way I understand all this stuff.


#4

The first 2 are correct but not semicolons after ifs:
http://discuss.codecademy.com/t/conditions-blocks-and-semicolons/2176?u=haxor789