JavaScript Basics: Your First Step Into the Logic World
“No JavaScript? Congrats, you built a digital brochure.”
✨ What is JavaScript?
JavaScript is the programming language that makes your website alive. Button clicks, animations, form validation, fetching data from APIs — yeah, that’s all JavaScript doing overtime.
🧠 Why JavaScript matters
- Runs directly in the browser (client-side)
- Makes websites interactive
- Dynamic and flexible
- Mandatory skill for front-end developers
Without JavaScript, your website is static, silent, and kinda sad.
🧩 How to Run JavaScript
There are three ways to use JavaScript in HTML:
1. Inline JavaScript
<button onclick="alert('Hello!')">Click me</button>
⚠️ Only okay for demos. Not for real projects.
2. Internal JavaScript
<script>
console.log("Hello from internal JS!");
</script>
3. External JavaScript ✅ Best Practice
<script src="script.js"></script>
Clean, scalable, and future-you will thank you.
🖥️ Meet Your Best Friend: console.log()
Your browser has a developer console. This is where JavaScript talks to you.
console.log("Testing... 1 2 3");
- Debug errors
- Check variable values
- Understand program flow
- Question your life choices
🥚 Variables — Where Data Lives
Modern JavaScript uses only two keywords:
- let → value can change
- const → value stays forever
let age = 20;
const name = "Syfa";
age = 21; // valid
name = "Budi"; // error 🚫
Forget var. That era is over.
🎭 JavaScript Data Types
| Type | Example |
|---|---|
| String | "Hello" |
| Number | 24, 3.14 |
| Boolean | true / false |
| Null | null |
| Undefined | undefined |
| Object | { name: "Syfa" } |
➗ Basic Operators
let a = 10;
let b = 3;
console.log(a + b);
console.log(a - b);
console.log(a * b);
console.log(a / b);
console.log(a % b);
Simple math now, serious logic later.
🧪 Your First Mini Program
let name = "Syfa";
let age = 20;
console.log(`Hello ${name}, you are ${age} years old`);
Template literals = clean, modern, and actually readable.
