Is it necessary to end a code with ; in javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is it necessary to end a code with ; in javascript

Pls tell where to use it in variable , constants and where else

25th Dec 2022, 11:29 AM
Harsh Rana
Harsh Rana - avatar
2 Answers
+ 2
No we don't have to, except in for loop for(let i = 0; i <= 10; i++) { } Here we chain statements and we need to use it But in other cases code will mostly work without it Browsers understand end of line as ";" So if you don't have anything after statement, ";" is not needed Make sure you stick to same style when coding, if you used already ";" in your code, then use it thought full code. Maybe some tools to minify code(or similar) will break if ";" is not used, so if you use this tools, read documentation and make sure it won't make problems, before you start to type your code.
25th Dec 2022, 1:07 PM
PanicS
PanicS - avatar
+ 1
If there is no need to put a special character at the end of the line, then we put ; function name(){ #here we do not put ; because there are curly braces# let x = 1; #this is a character here because we don't put a special character# }
25th Dec 2022, 11:51 AM
Knight
Knight - avatar