HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to JavaScriptVariables (let / const)Data TypesOperatorsStringsArraysObjectsConditions (if / else)Loops (for / while)FunctionsArrow Functions (=>)Array Methods (map / filter / reduce)
REFERENCE
📖 Overview
🖥️ Output & Console
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Array
🗂️ Object
🔁 Condition & Loop
🧩 Function
🔄 Type & Conversion
JavaScript›Introduction to JavaScript

Introduction to JavaScript

First step into JavaScript, the language of the web: printing with console.log, variables, and simple operations — line by line with colorful explanations.

Simple enough for a 5-year-old to understand

Your first output: console.log

In JavaScript, console.log is used to print something to the screen/console. It displays the value you write inside the parentheses.

Your first program
1
console.log("Hello!");
Prints the text inside the quotes to the console.
Output / InputPrints the text inside the quotes to the console.
Output / Input
💡 Hint: Putting a semicolon (;) at the end of lines is a good habit.

Let's write two lines

Example code
1
console.log("I am writing code");
First line.
Output / InputFirst line.
2
console.log("So much fun!");
Second line — they appear one below the other.
Output / InputSecond line — they appear one below the other.
Output / Input

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.Which one is used to write to the console in JavaScript?
2.Print exactly Hello World to the console.

🎯 Expected output: Hello World

Loading editor…

About this topic

JavaScript is the only programming language that runs in the browser. A dropdown menu on a page, validation done without submitting a form, a cart total updated without refreshing the page — they are all JavaScript. That is why it is a language everyone interested in the web has to learn.

The first step is to output text using console.log. This command doesn't write to the screen, but to the browser's developer console; you open the console with the F12 key. console.log is not just an introductory exercise, but the debugging tool you will use most in your professional life.

What you will learn

  • to output to the console using console.log
  • to define variables and the role of the semicolon
  • to write strings inside quotation marks
  • to combine text with a variable using template literals
  • how to link code to an HTML page

When to use?

You use console.log to see what is inside a variable, verify that a function is actually being called, and inspect the data returned by a request. The browser console is also where errors appear; when you see a red line, that's where troubleshooting starts.

Common mistakes

Wrong

console.log(Merhaba)

Hello written without quotation marks is considered a variable name. Since no such variable exists, the browser throws the "Uncaught ReferenceError: Hello is not defined" error.

Correct

console.log("Hello")

Wrong

console.Log("Hello")

JavaScript is case-sensitive; the method name is log, not Log. You will get the "TypeError: console.Log is not a function" error. The same sensitivity applies to variable names.

Correct

console.log("Hello")

Wrong

<script src="app.js">
  console.log("Hello")
</script>

Code INSIDE a script tag that has a src attribute is not executed; the browser only loads the file. Silently nothing happens, and you won't see an error either. Inline code requires a separate script tag.

Correct

<script src="app.js"></script>
<script>
  console.log("Hello")
</script>

Frequently asked questions

How do I see my code in the console?

Press the F12 key in the browser and go to the Console tab. console.log outputs and errors appear there. The file name and line number next to the error message show the exact location of the issue; this is the first place to look when debugging.

Is the semicolon mandatory?

Not mandatory; JavaScript handles line endings automatically in most cases. However, in some rare situations, this auto-completion produces unexpected results. Practical advice: in a project, either always put them or never put them, don't mix.

Where should I put the code in HTML?

Just before the closing of the body tag or inside the head with the defer attribute. If you put it in the head without defer, the code will try to access HTML elements that haven't been created yet and you will get null errors.

Summary

JavaScript is the language of the browser and your first tool is console.log — the command you will use most both while learning and in professional life. When linking code to the page, using defer or placing the script tag at the end of the body prevents premature execution errors.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code