What is the difference between semicolons in JavaScript and in Python?

PythonServer Side ProgrammingProgramming

Semicolons are optional in Python. In JavaScript, it s also optional, but it is a good practice to add it and is sometimes a necessity in case of some statements. If in these statements, a semicolon is not inserted, then one gets automatically added, but it may change the purpose of the code. This is called Automatic Semicolon Insertion.

Let’s see how −

The following is your code, with no semicolons:

function sub (p, q) {
   return
   p + q
}

The above will actually be considered as the following −

function sub (p, q) {
   return;
   p + q;
}
raja
Published on 09-Jan-2018 09:22:00
Advertisements