Language: EN

como-empezar-con-javascript

Our First JavaScript Program

Let’s get to work and make Our first program in JavaScript!. You’ll see that one of the best things about JavaScript is that starting is very easy and straightforward.

For this we need:

  • Our code
  • Something to run our code
  • A program to write our code

Let’s look at each of these below 👇.

Our First Code

The Hello world is a small program commonly used as a basic example. It won’t be much, just showing a message (but this way we’ll get the hang of it).

Our code is simply the following.

console.log("Hello from LuisLlamas.es");
  • console.log is a JavaScript function used to send messages to the browser console.
  • The string Hello from LuisLlamas.es is the argument passed to the console.log function.
  • The string is enclosed in double quotes to indicate that it is a text string.

Don’t worry about each thing for now. We’ll go over them little by little (that’s what this great course is for 😜).

Running JavaScript

Now we need something that takes our code and runs it. This is called a runtime environment.

One of the good things about JavaScript is how easy it is to get started. In fact, you don’t need to install anything additional. Your web browser (Chrome, Firefox, Safari) has an interpreter where you can run small snippets of code.

To try it out, open your web browser and access the browser console by pressing Ctrl + Shift + I (or Cmd + Option + I on macOS).

Now go to the Console tab and there you can directly type your code:

console.log("Hello from LuisLlamas.es");

When you press Enter you’ll see that the command executes, and the message is displayed.

javascript-hola-mundo

Congratulations, you’ve executed your first piece of JavaScript code! 🎉🥳.

Of course, this is great for a quick test, and it’s very useful on many occasions. But generally, we’re not going to run our code here (it wouldn’t be very practical 😅)


In the next article, we’ll see “Where the heck can I run my JavaScript code” read more ⯈

Installing a Code Editor

When we get into more complicated projects (this has been a simple one) we will also need a program to write our code.

As I said, one good thing about JavaScript is that everything is very easy. In fact, any simple text editor would work.

But the norm is that we use an IDE (Integrated Development Environment). Which is a text editor but with additional features specific for programmers.

The most common is Visual Studio Code, which is a lightweight and highly customizable editor. If you don’t know what that is, or if you don’t have it installed, check out this entry