First JavaScript program

javascript my first program

First javaScript program

So let’s now write our very first line of JavaScript code. And for now, we will do that in the browser developer tools. So just to get started as quickly as possible, we will then switch to the code editor. So make sure to open up Google Chrome. And then, there are three ways in which we can open up the Chrome Developer Tools. First, we can hit Command, Option J, on the keyboard, and that’s on Mac. So on Windows, that’s going to be Ctrl, Alt J. And so this will then open up the console.

Java Script first programJavaScript developer console allows us to write and test JavaScript code. So it’s beneficial during development, for example, to fix errors. By using the console, we can do many things

 

 

So all of the tabs are the developer tools. But we are just interested in the console only. Now another way of opening the developer tools is by right-clicking in then inspecting, which will bring us here to the Elements tab. And then from there, we can go to the console. And the third way, and I’m showing you all of them because I know that different people like to do it in different ways. So the third way is to come here to the Chrome menu. And then in there, we go to View, developer, and then JavaScript console.

now, just to get started, let’s use the console because it’s a good and easy way to write some javascript here.

So let’s write an alert,

alert(“Hello World”);

With just a so-called JavaScript function, then open up parenthesis, and without a space between attention and parenthesis, and then we write a so-called string. So which is text. And let’s write hello, world. So that’s the standard way of learning programming in any programming language. Then we write the closing parenthesis, and then let’s hit return or enter. And you’ll see that JavaScript gave us this pop-up window here, which has Hello world, just as we type here in our string in our code. Great. So that’s your very first line of JavaScript code right there. So any code that we write here and then hit return will immediately get evaluated.

 

We can do a lot more. So let’s write some more JavaScript code, which of course, you do not need to understand yet; I just wanted to show some stuff that we can do; we will go into how everything works as we progress through this section. Okay. So to experiment a little bit, let’s write a so-called variable.

try Some coding
 let myvar=”Jordan”;

 And so once more, we are writing a string here. So text, that we will do if an open parenthesis myVar=” Mike”; Then we want an alert window, as we saw before, saying “Jordan”. And if I hit now return, we get this window, which will say, Mike. Okay. So again, I will explain all these concepts in how this works, But for now, I hope that you can see the logic that we defined.

Now another thing that we can do is do simple math operations, let’s say just 50+5050-20, let’s say, hit return, then here we get the result. So basically, we can use this as a calculator and hope that you can see how useful this will become later down the road. Okay, and that’s it for now. So I hope that this gave you an excellent first taste of the language and everything that is a hat. So if you want, you can experiment a little more with this, or you can move on right to the following article, where we will learn about file linking and variables in detail.

Read Also: What is JavaScript?

 

 

 

 

Leave a Reply

Your email address will not be published.

Get a quote

Let’s Shedule a meeting with our core team

Get Quote

Archives