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; }