Few rules should be known before writing a javascript code which are stated below.
<script> document.write("<h1>Hello world!!!</h1>"); </script>
The example above uses document.write() method which is a javascript command that can be used to print any texts in the web page. It's placed in the middle of the HTML contents instead of placing inside the <head> or right above the </body> markups and is highly useful when you want to display some message to your website users but don't want to use pop up box. It will print the texts wherever you place the code itself. You can also write HTML markups with this command.
As stated earlier, javascript is case sensitive and treats similar entities with different sentencecases like hello and Hello as different terms. Lets see it with examples.
<script> x = 3; x = 7; result = x + x; document.write(result); </script>
Result: 14
The first value of variable x is overridden by the second one because both variables are treated as one and in programming the value defined at the last overrides the first one.
<script> x = 3; X = 7; result = x + X; document.write(result); </script>
Result: 10
Both variables are recognized as separate entities here. So, the output is the desired one.
The best option while declaring variables would be to go with camel case like javaScriptTutorial while you can opt for any cases but you need to keep consistency within your scripts.
Leave a comment