Do I need to use a semicolon?

the concept is that you can skip semi colon after line break means that when we write
console.log(45)
then hit enter key and goes to new line then JavaScript engine will put semi colon by itself . You do not need in this case

It is not necessary as long as the hundreds are not the same line, it is also good practice to use a semicolon.

great explanation . thnks

1 Like

Absolutely, thank you!!

1 Like

Its not necessary to put semicolon but if you put semicolon then it will be the good practice to any author of the project

It is required in JS but the interpreter/browser automatically puts them in when you run the program. Roy explains this in a lot more detail than I ever can: FAQ: Loops - Nested Loops - #231 by mtf. They are still preferred thought.

Yeah, the result shows us fine but a semicolon is required, to clear that is the end of our line.

semi colon shows the end of line in programming which is a good habit of writing code clearly even if it’s not required in JavaScript.

yes because without the semicolon the command will not execute

Not so. The semi-colon has nothing to do with execution. It is a parsing token that tells the interpreter to stop parsing and move on to the compile phase. If the code has a line break, JS will consider that as an end of statement, instead.

It doesn’t print an error if you don’t place a semicolon after the print statement consol.log( ). Even if you place a semicolon, or not you are good.

The same happened to me, I’m guessing it is.

I tried to do some more research after reading your comment. I think I understand now, but the use of the words command and statement keep on confusing me. What’s the difference?

Easiest way to sort them apart is to remember there are no commands in a program, only statements. A command can only be sent via the terminal or shell interface. It’s where the term, command line comes from.

Command line is associated with the OS; console is associated with the language API.

1 Like

Thank you!
To check I understood correctly:
Commands are operating system instructions written in f.ex. the shell.

How many interpretation steps are needed starting with the Javascript Code?

Also, sorry, I had to research API and I’ve found that APIs access information from the OS. So the console „commands“ (or „statements“?) the API and the API „commands“ the OS, is that correct?

1 Like

We have/need interfaces at all levels, kernel on up. JavaScript is accessing lower level APIs at the compilation/execution stage, but affording us access to it at the parser/interpreter level. In other words there are interfaces at all levels. Programming languages afford us the ability to write source code with a higher level API that is human readable. starting from Assembler, on up.

The JavaScript engine is very likely written in a low level, C like language, or emergent species, That program gives support to all the features we need to access, console and session instance.

1 Like

yes, you must add a semicolon to let the compiler know where the line ends.

I have no idea about the semicolon, but as i am working currently on JS it needs to put semicolon at the end.

Using a semicolon at the end of your code shows the best practices when coding.

thanks for the explanation

1 Like