Programming Basics

What Is JavaScript? A Beginner-Friendly Introduction

JavaScript is a very popular programming language, especially for websites. It lets websites react to user actions, such as clicking a button, showing messages, validating input, and performing calculations.

Published: Jun 8, 2026Updated: Jun 8, 2026Reading time: 5 minViews: 0
JavaScriptBeginnerProgrammingVariablesconsole.logif-elseletconstWeb Development

💡Key Takeaways

  • JavaScript is a very popular programming language, especially for websites.
  • It lets websites react to user actions, such as clicking a button, showing messages, validating input, and performing calculations.

Topic: basic JavaScript knowledge
Audience: people who are new to programming
Level: very beginner-friendly, with simple examples
Main ideas: what JavaScript is, where it runs, console.log, variables, simple calculations
Image format: internet-hosted JPEG image, no base64 embedding, no SVG

Programming code illustration
Programming code illustration

Image source: Wikimedia Commons — Colorful code (Unsplash).jpg.
Photo author: Markus Spiske.
License: CC0 1.0 Public Domain Dedication according to the Wikimedia Commons page.
Original image page: https://commons.wikimedia.org/wiki/File:Colorful_code_(Unsplash).jpg
Direct display image URL: https://upload.wikimedia.org/wikipedia/commons/thumb/9/94/Colorful_code_%28Unsplash%29.jpg/1280px-Colorful_code_%28Unsplash%29.jpg

1. What is JavaScript?

JavaScript is a very popular programming language, especially for websites.

A simple way to think about a website:

Example

HTML is like the structure of a house. CSS is like the paint and decoration. JavaScript is like the electricity, switches, and actions inside the house.

For example:

  • HTML creates a button.
  • CSS makes the button look nice.
  • JavaScript makes something happen when the user clicks the button.

On a shopping website, when you click “Add to cart,” the cart number may change. That kind of action can be handled with JavaScript.

2. What is JavaScript used for?

Beginners can understand JavaScript through familiar tasks:

  • show a message when the user clicks a button;
  • check whether the user entered an email;
  • calculate the total price in a cart;
  • change page content without reloading the whole page;
  • open and close menus;
  • send data from a website to a server.

At first, you do not need to learn everything. Just remember: JavaScript helps a website react to the user.

3. Your first JavaScript line

A common first line is:

JAVASCRIPT
console.log("Hello JavaScript!");

This means:

TEXT
Print "Hello JavaScript!" to the browser's checking area.

Result:

Example

Hello JavaScript!

console.log() is often used to check what your program is doing. Beginners should use it often to observe results.

4. What is console.log?

Imagine you are cooking. While cooking, you taste the food to see how it is going.

console.log() is like “tasting” in programming. It helps you temporarily see values inside your program.

Example:

JAVASCRIPT
console.log(10);
console.log("An");
console.log(10 + 5);

Result:

Example

10 An 15

Simple meaning:

TEXT
console.log = print it so I can check

5. What is a variable in JavaScript?

A variable is a name that stores a value.

Real-life example:

Example

Name: An Age: 18 City: Hanoi

In JavaScript:

JAVASCRIPT
let name = "An";
let age = 18;
let city = "Hanoi";

How to read it:

Example

Create a name called name and store "An". Create a name called age and store 18. Create a name called city and store "Hanoi".

Then you can print them:

JAVASCRIPT
console.log(name);
console.log(age);
console.log(city);

Result:

Example

An 18 Hanoi

6. Why do we need variables?

Variables let us store information and use it again.

Without variables:

JAVASCRIPT
console.log(25000 * 3);

With variables:

JAVASCRIPT
let price = 25000;
let quantity = 3;
let total = price * quantity;

console.log(total);

Result:

Example

75000

The version with variables is easier to read:

Example

price is the item price. quantity is the number of items. total is the final amount.

If the price or quantity changes later, you only need to change the variable value.

7. What are let and const?

Beginners will often see let and const.

Simple explanation:

TEXT
let = use it when the value may change
const = use it when the value should not change

Example with let:

JAVASCRIPT
let age = 18;
age = 19;

console.log(age);

Result:

Example

19

Example with const:

JAVASCRIPT
const country = "Vietnam";

console.log(country);

Simple memory tip:

Example

Use let when the value may change. Use const when the value should stay the same.

8. Text and numbers

JavaScript has many kinds of data, but beginners can start with two familiar ones: text and numbers.

Text uses quotation marks:

JAVASCRIPT
let name = "An";
let message = "Hello";

Numbers do not need quotation marks:

JAVASCRIPT
let age = 18;
let price = 25000;

Common confusion:

JAVASCRIPT
let a = 10;
let b = 20;

console.log(a + b);

Result:

Example

30

But:

JAVASCRIPT
let a = "10";
let b = "20";

console.log(a + b);

Result:

Example

1020

Because "10" and "20" have quotation marks, JavaScript treats them as text. With text, + joins the values together.

Memory tip:

Example

10 is a number. "10" is text.

9. Simple example: calculating a purchase total

A book costs 45,000, and you buy 2 books.

JAVASCRIPT
let price = 45000;
let quantity = 2;
let total = price * quantity;

console.log(total);

Result:

Example

90000

Line-by-line:

JAVASCRIPT
let price = 45000;

Create price to store the price of one book.

JAVASCRIPT
let quantity = 2;

Create quantity to store how many books you buy.

JAVASCRIPT
let total = price * quantity;

Create total to store the final price.

JAVASCRIPT
console.log(total);

Print the total so you can check it.

10. Simple example: greeting a user

JAVASCRIPT
let name = "An";

console.log("Hello, " + name + "!");

Result:

Example

Hello, An!

Here, + joins text together.

Simple idea:

Example

"Hello, " + "An" + "!"

becomes:

Example

Hello, An!

11. A very simple condition

A condition helps a program choose what to do.

Real-life example:

TEXT
If age is 18 or more, the person is an adult.
Otherwise, the person is not an adult yet.

In JavaScript:

JAVASCRIPT
let age = 20;

if (age >= 18) {
    console.log("Adult");
} else {
    console.log("Not adult yet");
}

Result:

Example

Adult

Explanation:

  • if means if.
  • age >= 18 asks whether age is at least 18.
  • If it is true, print "Adult".
  • If it is false, run the else part.

12. Common beginner mistakes

Mistake 1: Forgetting quotation marks for text

Wrong:

JAVASCRIPT
let name = An;

Correct:

JAVASCRIPT
let name = "An";

Text needs quotation marks.

Mistake 2: Confusing numbers and text

JAVASCRIPT
let age = "18";

This stores age as text, not as a number.

If you want to calculate with age, write:

JAVASCRIPT
let age = 18;

Mistake 3: Forgetting semicolons

JavaScript can often run without ;, but beginners should write clearly:

JAVASCRIPT
let age = 18;
console.log(age);

Mistake 4: Using unclear variable names

Less clear:

JAVASCRIPT
let x = 25000;
let y = 3;
let z = x * y;

Clearer:

JAVASCRIPT
let price = 25000;
let quantity = 3;
let total = price * quantity;

Clear names make code easier to read.

13. How beginners should learn JavaScript

Do not learn too many things at once. A good order is:

  1. console.log() to see results.
  2. Variables: let, const.
  3. Text and numbers.
  4. Simple calculations.
  5. if / else conditions.
  6. Functions.
  7. Lists.
  8. Working with buttons on a web page.

Learn each part with small examples. You do not need to understand everything at once.

14. Small exercises

Exercise 1

Write code that prints:

Example

Hello JavaScript!

Exercise 2

Create a variable name with your name, then print:

TEXT
Hello, <your name>!

Exercise 3

Create:

TEXT
price = 30000
quantity = 4

Calculate the total and print it.

Exercise 4

Create a variable age. If age >= 18, print "Adult". Otherwise, print "Not adult yet".

15. Suggested answers

Answer 1

JAVASCRIPT
console.log("Hello JavaScript!");

Answer 2

JAVASCRIPT
let name = "An";

console.log("Hello, " + name + "!");

Answer 3

JAVASCRIPT
let price = 30000;
let quantity = 4;
let total = price * quantity;

console.log(total);

Result:

Example

120000

Answer 4

JAVASCRIPT
let age = 18;

if (age >= 18) {
    console.log("Adult");
} else {
    console.log("Not adult yet");
}

16. Quick memory notes

JavaScript helps websites react to users.

console.log() prints a result so you can check it.

A variable is a name that stores a value.

let is for values that may change.

const is for values that should stay the same.

Text uses quotation marks. Numbers do not.

if / else helps a program choose what to do.

17. Conclusion

JavaScript does not need to start with difficult ideas. For beginners, the first steps are simple:

TEXT
Write one line of code.
Print the result.
Store information in variables.
Do simple calculations.
Let the program choose with a condition.

Once these ideas feel familiar, learning functions, lists, and web page interaction becomes much easier.

SEO title suggestions

  • What Is JavaScript? A Beginner-Friendly Introduction
  • Learn Basic JavaScript: console.log, Variables, and First Examples
  • JavaScript for Beginners: Text, Numbers, Variables, and Conditions
  • Start Learning JavaScript From Zero

SEO meta description

A beginner-friendly JavaScript introduction explaining console.log, variables, let, const, text, numbers, simple calculations, if else conditions, and practice exercises.

References

  1. MDN Web Docs — JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript
  2. MDN Web Docs — What is JavaScript?: https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/What_is_JavaScript
  3. MDN Web Docs — Variables: https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/Variables
  4. MDN Web Docs — console.log(): https://developer.mozilla.org/en-US/docs/Web/API/console/log_static
  5. MDN Web Docs — Expressions and operators: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators
  6. Wikimedia Commons — programming image: https://commons.wikimedia.org/wiki/File:Colorful_code_(Unsplash).jpg
PR

Written by PixelRouter Editorial Team

We publish deep, authoritative guides on AI infrastructure, API gateway security, cloud financial management, and system optimizations for developers.

FAQ

What is JavaScript?

JavaScript is a very popular programming language that adds interactivity to websites, allowing them to react to user actions such as clicking a button or updating a cart.

What does console.log do?

console.log() prints a value to the browser’s console so you can see the result of your code and check what the program is doing.

How do I declare a variable in JavaScript?

You can declare a variable using let or const, for example: let name = "An"; const country = "Vietnam".

What is the difference between let and const?

let is used when the variable’s value may change, while const is used when the value should stay the same.

How can I perform a simple calculation in JavaScript?

Create variables for the numbers and use arithmetic operators, e.g., let total = price * quantity; console.log(total);

How does an if/else condition work in JavaScript?

An if statement checks a condition; if it’s true, the code inside the if block runs, otherwise the code inside the else block runs.