Why it is showing error when i am adding semicolon after declaring variable


#1
var foodDemand = function(food);
{console.log("I want to eat" + " " + food);
};
foodDemand("Pizza");

#2

You dont always need ; after every line of code. You only need them after every line of code in the { }. The reason is because in the { } its like periods for the computer just like writing in real life.

Your code:

var foodDemand = function(food);
{console.log("I want to eat" + " " + food);
};
foodDemand("Pizza");

What you need to fix:

var foodDemand = function(food)
{console.log("I want to eat" + " " + food);
}
foodDemand("Pizza")

You should be able to notice what you did wrong.

Hope it helped.


#3

In terms of function using the semicolon after () is like setting the period in the middle of the sentence.


#4

try this code it worked for me

var foodDemand = function(food){
console.log('I want to eat' + ' ' + food);

};
foodDemand('food');