We used the following 2 commands:
- alert ('Hello World');
- document.write ('Hello World');
With the first command we get an output of the following content on the screen in a separate pop-up window and with the second output directly in the content area of the browser window.
Order of processing our commands
The program is processed from top to bottom. That's why we see “HalloWelt” as an output. If a program were to run from bottom to top, “WorldHello” would have to be output, which would not be particularly logical.
Although it is logical, it still has to be mentioned once.
The inconspicuous semicolon at the end of each command is extremely important. This separates the command from the following.
Therefore we could write all commands on one line and we get the same result in the output.
But only if we don't accidentally forget the delimiting semicolon. In the following example we don't get any output and so we are surprised:
We do not receive an error message directly or any output. The error message "Uncaught Syntax Error: unexpected identifier" is hidden deep in the executing browser. How we get this hidden error message visible, comes in a following chapter.
Now let's move on to the basic structure.
ALWAYS include a semicolon at the end to avoid unpleasant surprises.
It is often clever to look at commands from right to left. In our example there is an output:
Next to our semicolon is the output text in round brackets and in quotation marks.
The quotation marks are important because this is text that we want to output. We don't yet know any variables - in the Variables chapter we see that otherwise the text would be understood as a variable.
The type of quotation marks
The type of quotation marks within the brackets is irrelevant for pure text output - the main thing is that there are quotation marks. So we can use double quotation marks (") as well as single quotation marks ('). It is only important that the same kind of quotation marks are always used. A combination of double and single quotation marks such as goes wrong!
So if something goes wrong here, look carefully whether and whether the correct quotation marks are used.
In our examples an output should be made, regardless of whether it is above or above.
This is the common, space-saving variant that all programmers normally use.
If you want to confuse old hands among programmers, insert spaces.
Funnily enough, it works in the browser - but it's not really clear. So just stick to the conventions.
Missing space in the output
Anyone who has wondered why the space between our words "Hello" and "World" was missing in the output - here is the explanation:
The browser outputs exactly what we ask of it on the screen.
If we want a space between "Hello World", then we have to include this in our code:
- What are the best orphanages in Boston
- ORACLE ADF online training 1
- Do you think Mike Shinoda is underestimated?
- What is the GATE curriculum for EEE
- What is neon
- What are some characteristics of punk music
- When will people have enough
- How can greed be good
- What is self marketing
- How to make deer attractants
- What is an object program
- Makes eating honey fat
- How is Bharati Vidyapeeth for electrical engineering
- What other musicians deserve a biography
- Why do Kashmiris harass Indian soldiers
- Why is Sam Smith always so sad
- How do you treat early stroke symptoms
- What are tips for a Dartmouth interview
- Has Zimbabwe done enough to control inflation
- There are free online photography courses
- Is circumcision performed on babies using anesthetics?
- What is the best career option
- How can I meet the Indian Prime Minister
- Why are canvas shoes called that