Back
LearnJavaScript From ZeroHow to write your first line of code

How to write your first line of code

2 min read

Let us write your first line — right now

Open any webpage. Press F12 on your keyboard (or right-click anywhere and choose Inspect). A panel opens up. Click the tab that says Console.

That console is a place where you can talk to JavaScript directly. Type this and press Enter:

console.log("Hello, world!");

You just wrote JavaScript! console.log(...) is JavaScript's way of saying "print this so I can see it." Whatever you put inside the quotes shows up.

What is actually happening here?

Let me break that single line down, piece by piece:

  • console → think of it as a notepad for developers.
  • .log() → the action: "write something down".
  • "Hello, world!" → the message (text always goes inside quotes).
  • ; → a full stop. It tells JavaScript "this instruction is finished".

Now try changing it

Do not just copy — play with it. Type your own name:

console.log("My name is Govind");
console.log(5 + 3);

Notice the second line has no quotes around 5 + 3. So JavaScript calculates it and prints 8. But this one:

console.log("5 + 3");

...prints 5 + 3 as plain text, because quotes mean "treat this as words, not maths".

Why does this tiny thing matter? Because this one idea — quotes mean text, no quotes mean a real value — will save you from a hundred bugs later. Remember it.

That is it. You are officially writing code now. Next, we will learn how to store information so our programs can remember things.

Tip