5 Most Common Mistakes DevOps Engineers Make and How to Avoid Them

DevOps and its resulting technical and cultural practices are being adopted in more companies worldwide every day. This article will examine teams’ most common mistakes while implementing these…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Introducing yourself to JavaScript 3

JavaScript Fundamentals: Hello JavaScript World

In learning any programming language, the first program you will always write is the “Hello World” program. The “Hello World” program is actually the simplest program you will ever write in JavaScript and in every other language. Brian Kernighan actually wrote the first “hello, worldprogram as part of the documentation for the BCPL programming language developed by Martin Richards. BCPL was used while C was being developed at Bell Labs a few years before the publication of Kernighan and Ritchie’s C book in 1972.

Remember that JavaScript must be “embedded” inside an HTML file and in the last article, we ended up with a question “How can i insert JS to HTML?”.

JavaScript code can be inserted into a HTML file by using the <script> tag. The script tag can be nested or placed in the <head> or <body> of the HTML document. Now we know how to insert JavaScript using the script tag, let’s make a program that prints out “Hello JavaScript World” in a dialog box.

We would use the JavaScript window.alert() method. A method is an action that can be performed on objects. The alert() — same thing as window.alert() displays a dialog box with a specified message and an OK button. The specified message in our program would be “Hello JavaScript World”. Also notice in the code above that the <script> tag has a HTML source attribute (src = “script.js”) but for now we would ignore it.

We’ve added the alert() method and inside the parenthesis, we placed a string. A string is any text enclosed in quotation marks. Let’s see the result.

Perfect! your first JavaScript program just ran.

Let’s use the <script> tag but remove the JavaScript code from the HTML file. In bigger programs, it is best practice for your JavaScript code to be separate from your HTML code and we can achieve this by using HTML attributes — HTML attribute is a modifier of an HTML element type. An attribute either modifies the default functionality of an element type or provides functionality to certain element types unable to function correctly without them. In our case, we would be using the src attribute. The src attribute in HTML specifies a URL (Uniform Resource Locator) of a file. The online text editor I am using in this tutorial has a file called script.js ( Remember .js makes it a JavaScript file). I would write the JavaScript code in the script.js file and use the src attribute to link it to the HTML file.

We added the src attribute here.

This is the JavaScript file — script.js. Here we do not need to use the <script> tag because this is more like JavaScript’s home and you could write any thing JavaScript with freedom.

It works perfectly.

Note: You should not use the src attribute in the script tag and still write JavaScript code between the script tag.

Don’t do this. It might work but it’s not best practice.

Now in this article, i did not show you how to create a separate file on your text editor and save it as script.js. This was intentional so you could enjoy the rigors of self learning! We now know that :-

In our next article, we would be learning Variables in JavaScript. If you have not been following the series, below are links to previous articles.

Introducing yourself to JavaScript 1

Introducing yourself to JavaScript 2

Add a comment

Related posts:

Login Amazon EC2 as root using authorization keys

Follow the steps below.. “Login Amazon EC2 as root using authorization keys” is published by Ehsanul Hoque in The Devs Tech.

Aspire Breeze 2 AIO Kit

Aspire Breeze 2 AIO Kit geliştirilmiş doldurma yöntemi ile yeniden tasarlanmıştır. Cihaz detayları için https://esigarauzmani.com/urun/aspire-breeze-2-aio-kit/ linki tıklayınız.