JavaScript Semicolons

Every line in a JavaScript program is optionally terminated using semicolons. Unless if the statements are to be in single.

I said optionally, because the JavaScript interpreter is smart enough to introduce semicolons for you.

In most cases, you can omit semicolons altogether from your programs.

This fact is very controversial, and you'll always find code that uses semicolons and code that does not.

My personal preference is to always use semicolons for your code. Because it will always help you especially while trying to learn langtuage like Java and C++ are must examples in this part.

Example:


var cat = "Samira";
var cat = "Samira"
            

Both the above code are valid and they will run perfectly.

Let's create one real-time example for better understanding. Check the below code.

Example

// Try-catch block
var cat_1 = "Samira";
var cat_2 = "Samira"

console.log(cat_1);
console.log(cat_2);