Javascript Course for Beginners

Why Javascript?
Javascript Course for Beginners

    As we all know that we can build beautiful websites using HTML and CSS. But the problem is such pages are static only which means users can just scroll up and down, click on the links. There's no interaction with the users.

    Now we can make these static pages dynamic by adding a layer of interactivity with the help of Javascript.

Where to write Javascript code:

    Javascript code can be written inside script tags. Those JS codes look just like normal HTML elements and they can be placed either in the head section or in the body section. The best practice is to include the script tags at the end of the body element.

    <!DOCTYPE HTML>
    <html>
        <head>
            <script>

                // Javascript code can be written here

            </script>
        </head>
        <body>
            <!-- page content  -->
            <script>

                // Javascript code can be written here

            </script>
        </body>
    </html>

    However, the best practice is to write Javascript code is in separate.js files. Now the script tag will act as a link to that external .js file.

    <body>

        <!-- html page  -->

        <script src='scripts.js'></script>

    </body>
Writing the first Javascript statements:

Now we will write some javascript statements inside the script tag.
  <body>
	<!-- html page  -->
	<script>
        
		alert('Sending a message via alert');

		console.log('Sending a message via the console');
            
	</script>
  </body>
            The message passed through the alert function is shown on a popup on the page and the message sent through the console.log function can be seen on the browser's inspector.

            In general, whatever sent through the console.log function is not for the users. This is used by the programmers to identify the mistakes or how javascript code is performing through the browser inspector.

No comments:

Post a Comment