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.
💡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

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
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:
console.log("Hello JavaScript!");
This means:
Print "Hello JavaScript!" to the browser's checking area.
Result:
Example
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:
console.log(10);
console.log("An");
console.log(10 + 5);
Result:
Example
Simple meaning:
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
In JavaScript:
let name = "An";
let age = 18;
let city = "Hanoi";
How to read it:
Example
Then you can print them:
console.log(name);
console.log(age);
console.log(city);
Result:
Example
6. Why do we need variables?
Variables let us store information and use it again.
Without variables:
console.log(25000 * 3);
With variables:
let price = 25000;
let quantity = 3;
let total = price * quantity;
console.log(total);
Result:
Example
The version with variables is easier to read:
Example
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:
let = use it when the value may change
const = use it when the value should not change
Example with let:
let age = 18;
age = 19;
console.log(age);
Result:
Example
Example with const:
const country = "Vietnam";
console.log(country);
Simple memory tip:
Example
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:
let name = "An";
let message = "Hello";
Numbers do not need quotation marks:
let age = 18;
let price = 25000;
Common confusion:
let a = 10;
let b = 20;
console.log(a + b);
Result:
Example
But:
let a = "10";
let b = "20";
console.log(a + b);
Result:
Example
Because "10" and "20" have quotation marks, JavaScript treats them as text. With text, + joins the values together.
Memory tip:
Example
9. Simple example: calculating a purchase total
A book costs 45,000, and you buy 2 books.
let price = 45000;
let quantity = 2;
let total = price * quantity;
console.log(total);
Result:
Example
Line-by-line:
let price = 45000;
Create price to store the price of one book.
let quantity = 2;
Create quantity to store how many books you buy.
let total = price * quantity;
Create total to store the final price.
console.log(total);
Print the total so you can check it.
10. Simple example: greeting a user
let name = "An";
console.log("Hello, " + name + "!");
Result:
Example
Here, + joins text together.
Simple idea:
Example
becomes:
Example
11. A very simple condition
A condition helps a program choose what to do.
Real-life example:
If age is 18 or more, the person is an adult.
Otherwise, the person is not an adult yet.
In JavaScript:
let age = 20;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Not adult yet");
}
Result:
Example
Explanation:
ifmeans if.age >= 18asks whether age is at least 18.- If it is true, print
"Adult". - If it is false, run the
elsepart.
12. Common beginner mistakes
Mistake 1: Forgetting quotation marks for text
Wrong:
let name = An;
Correct:
let name = "An";
Text needs quotation marks.
Mistake 2: Confusing numbers and text
let age = "18";
This stores age as text, not as a number.
If you want to calculate with age, write:
let age = 18;
Mistake 3: Forgetting semicolons
JavaScript can often run without ;, but beginners should write clearly:
let age = 18;
console.log(age);
Mistake 4: Using unclear variable names
Less clear:
let x = 25000;
let y = 3;
let z = x * y;
Clearer:
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:
console.log()to see results.- Variables:
let,const. - Text and numbers.
- Simple calculations.
if / elseconditions.- Functions.
- Lists.
- 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
Exercise 2
Create a variable name with your name, then print:
Hello, <your name>!
Exercise 3
Create:
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
console.log("Hello JavaScript!");
Answer 2
let name = "An";
console.log("Hello, " + name + "!");
Answer 3
let price = 30000;
let quantity = 4;
let total = price * quantity;
console.log(total);
Result:
Example
Answer 4
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:
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
- MDN Web Docs — JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript
- MDN Web Docs — What is JavaScript?: https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/What_is_JavaScript
- MDN Web Docs — Variables: https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/Variables
- MDN Web Docs — console.log(): https://developer.mozilla.org/en-US/docs/Web/API/console/log_static
- MDN Web Docs — Expressions and operators: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators
- Wikimedia Commons — programming image: https://commons.wikimedia.org/wiki/File:Colorful_code_(Unsplash).jpg
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.