DEV Community

Cover image for [08 | JS 01] JavaScript Fundamentals: A Beginner-Friendly Guide
Anik Paul
Anik Paul

Posted on

[08 | JS 01] JavaScript Fundamentals: A Beginner-Friendly Guide

JavaScript is the language of the web - powering everything from simple interactions to full-fledged applications. If you're just getting started, this guide will help you understand the core concepts that form the foundation of JavaScript.

We'll walk through each topic with clear explanations and practical examples to help you learn confidently. Let's dive in! 👨‍💻


📚 Table of Contents

  1. Data Types
  2. Let, Const and Var
  3. Basic Operators
  4. Strings and Template Literals
  5. Taking Decisions: if/else
  6. The Conditional (Ternary) Operator
  7. Type Conversion and Type Coercion
  8. Truthy and Falsy Values
  9. Equality Operators (== vs ===)
  10. Boolean Logic
  11. Logical Operators
  12. Statements and Expressions

1. Data Types

In JavaScript, every value is either a primitive or an object. There are 7 primitive data types:

  • Number: Used for all numeric values (integers or decimals).
  let temperature = 36.5;
Enter fullscreen mode Exit fullscreen mode
  • String: Used for text.
  let favoriteMovie = "Interstellar";
Enter fullscreen mode Exit fullscreen mode
  • Boolean: Logical value (true or false).
  let hasTicket = false;
Enter fullscreen mode Exit fullscreen mode
  • Undefined: A variable declared but not assigned a value.
  let userStatus;
Enter fullscreen mode Exit fullscreen mode
  • Null: Intentionally empty value.
  let selectedSeat = null;
Enter fullscreen mode Exit fullscreen mode
  • Symbol (ES6): Unique and immutable value, used for object keys (rarely used by beginners).
  const id = Symbol("userID");
Enter fullscreen mode Exit fullscreen mode
  • BigInt (ES2020): For very large integers beyond the range of Number.
  const starsInGalaxy = 123456789012345678901234567890n;
Enter fullscreen mode Exit fullscreen mode

👉 JavaScript uses dynamic typing, meaning you don't need to declare the data type explicitly. The value determines the type, not the variable.

🔍 Use the typeof operator to check the type of a value:

console.log(typeof favoriteMovie); // 'string'
console.log(typeof starsInGalaxy); // 'bigint'
Enter fullscreen mode Exit fullscreen mode

2. Let, Const and Var

  • let: Allows reassigning the variable.
  let unreadMessages = 5;
  unreadMessages = 3;
Enter fullscreen mode Exit fullscreen mode
  • const: Cannot be reassigned. Must be initialized when declared.
  const PI = 3.14159;
Enter fullscreen mode Exit fullscreen mode
  • var: Works like let but is function-scoped. It's outdated and should generally be avoided.
  var userName = "Alice";
Enter fullscreen mode Exit fullscreen mode

✅ Use const by default and let only when reassignment is needed.


3. Basic Operators

  • Arithmetic Operators: +, -, *, /, %, **
  let totalPrice = 250 + 75 - 30 * 2; // 265
Enter fullscreen mode Exit fullscreen mode

** is exponentiation: 2 ** 3 → 8
% is remainder: 10 % 3 → 1

  • Assignment Operators: =, +=, -=, *=, **=, ++, --
  let steps = 1000;
  steps += 500; // 1500
  steps++;      // 1501
Enter fullscreen mode Exit fullscreen mode
  • Comparison Operators: <, <=, >, >=
  let isEligible = totalPrice > 200;
Enter fullscreen mode Exit fullscreen mode

📎 Want to learn how JavaScript decides which operator runs first?
Check out this Operator Precedence Table on MDN for a complete reference.


4. Strings and Template Literals

  • Template literals allow embedding variables and expressions using backticks:
const city = "Tokyo";
const days = 5;
console.log(`I'm visiting ${city} for ${days} days.`); // Output: I'm visiting Tokyo for 5 days.
Enter fullscreen mode Exit fullscreen mode

✏️ This is cleaner than traditional concatenation:

// Traditional way
console.log("I'm visiting " + city + " for " + days + " days."); // Output: I'm visiting Tokyo for 5 days.
Enter fullscreen mode Exit fullscreen mode
  • Multiline strings are also supported:
console.log(`Packing list:
- Passport
- Tickets
- Charger`);
Enter fullscreen mode Exit fullscreen mode

5. Taking Decisions: if/else

Conditional statements allow your program to make decisions.

const battery = 12;

if (battery >= 20) {
  console.log("You're good to go!");
} else {
  const needed = 20 - battery;
  console.log(`Charge at least ${needed}% more.`);
}
Enter fullscreen mode Exit fullscreen mode

✅ Output:

Charge at least 8% more.
Enter fullscreen mode Exit fullscreen mode

🧠 This is called a control structure because it controls which block of code runs based on conditions.

💡 You can also use else if for multiple conditions.


6. The Conditional (Ternary) Operator

A shorter way to write if/else statements:

const isWeekend = true;
const plan = isWeekend ? "go hiking" : "attend class";
console.log(`Today I will ${plan}.`); // Today I will go hiking.
Enter fullscreen mode Exit fullscreen mode
  • The syntax: condition ? valueIfTrue : valueIfFalse
  • It returns a value and can be used inside template literals.

7. Type Conversion vs Type Coercion

  • Type conversion: Manually converting data types.
  Number("42");   // 42
  String(false);  // 'false'
Enter fullscreen mode Exit fullscreen mode
  • Type coercion: JavaScript automatically converts types when needed.
  console.log('10' - '3');  // 7
  console.log('5' + 2);     // '52'
  console.log('6' * '3');   // 18
Enter fullscreen mode Exit fullscreen mode

👉 + triggers string coercion. Other operators usually convert strings to numbers.


8. Truthy and Falsy Values

JavaScript treats some values as falsy, meaning they become false in a boolean context:

  • 0, '', undefined, null, NaN

Everything else is truthy:

console.log(Boolean("🎉"));  // true
console.log(Boolean(""));    // false
Enter fullscreen mode Exit fullscreen mode

Used in conditions like:

if (userInput) {
  console.log("Processing input...");
}
Enter fullscreen mode Exit fullscreen mode

🔍 Tip: if (0) → false, if (1) → true


9. Equality Operators (== vs ===)

  • === (strict equality): No type coercion.
  18 === '18'; // false
Enter fullscreen mode Exit fullscreen mode
  • == (loose equality): Allows type coercion.
  18 == '18'; // true
Enter fullscreen mode Exit fullscreen mode

✅ Prefer === to avoid unexpected bugs.

const enteredPIN = "1234";

// strict
console.log(enteredPIN === 1234); // false

// loose
console.log(enteredPIN == 1234);  // true
Enter fullscreen mode Exit fullscreen mode

Also:

  • !== → strict not equal

10. Boolean Logic

Logical operators combine multiple boolean values:

  • && (AND): true if all are true
  • || (OR): true if any is true
  • ! (NOT): inverts a boolean
const isLoggedIn = true;
const isAdmin = false;

console.log(isLoggedIn && isAdmin); // false
Enter fullscreen mode Exit fullscreen mode

11. Logical Operators

const hasMic = true;
const hasCamera = true;

if (hasMic && hasCamera) {
  console.log("You're ready for the video call!"); // You're ready for the video call!
}
Enter fullscreen mode Exit fullscreen mode

You can use them in conditionals to make complex decisions.


12. Statements vs Expressions

  • Expressions produce values:
  8 + 2
  "Hi" + " there"
  5 > 3
Enter fullscreen mode Exit fullscreen mode
  • Statements perform actions but don't return values:
  if (5 > 3) {
    console.log("Math works!");
  }
Enter fullscreen mode Exit fullscreen mode

🔸 In template literals, you can only embed expressions - not full statements:

`Next year is ${2025 + 1}` // ✅
Enter fullscreen mode Exit fullscreen mode

Final Thoughts

These 12 topics form the foundation of JavaScript. Mastering them gives you a strong start in understanding how the language works.

As you continue learning, try building small projects and solving beginner challenges. Practice will help solidify your skills and grow your confidence.

Thanks for reading - and until next time, happy coding! 🚀👨‍💻


📬 Let’s Connect
🌐 Portfolio: paulanik.com
💼 LinkedIn: Anik Paul
🐙 GitHub: anikpaul99
📩 Email: hello@paulanik.com

Top comments (0)