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.

Javascript Course for Beginners

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

What is JavaScript?
  • JavaScript is an interpreted language. The browser interprets the JavaScript code embedded inside the web page, executes it, and displays the output. It is not compiled to any other form to be executed.
  • All the modern web browsers come along with the JavaScript Engine, this engine interprets the JavaScript code. There is no need to include any file or import any package inside the browser for JavaScript interpretation.
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 is 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

You might also like

Deploy your Django web app to Azure Web App using App Service - F1 free plan

In this post, we will look at how we can deploy our Django app using the Microsoft Azure app service - a free plan. You need an Azure accoun...