DEV Community

CodeWithDhanian
CodeWithDhanian

Posted on

# DAY 2 JAVASCRIPT CORE CONCEPTS CHEATSHEET

Introduction

Welcome to Day 2 of your JavaScript learning journey!

Today, we’ll dive deep into the Core Concepts of JavaScript that every beginner must know before building real-world projects.

Mastering these basics will make your coding life easier and help you understand advanced topics faster.


1. VARIABLES IN JAVASCRIPT

Variables are containers used to store data values.

Declaring Variables:

var name = "Dhanian";  // Old way
let age = 25;          // Modern & Recommended
const country = "Kenya"; // Cannot be changed
Enter fullscreen mode Exit fullscreen mode
Keyword Usage Can Reassign
var Avoid using Yes
let Recommended Yes
const Recommended No (constant)

2. DATA TYPES IN JAVASCRIPT

JavaScript has 8 basic data types:

  • String → Text → "Hello"
  • Number → 123, 45.6
  • Boolean → true or false
  • Undefined → Value not assigned
  • Null → Empty or unknown
  • Object → Complex data
  • Symbol → Unique identifiers
  • BigInt → Large integers

Example:

let name = "Dhanian";  // String
let age = 25;          // Number
let isOnline = true;   // Boolean
let city;              // Undefined
let car = null;        // Null
Enter fullscreen mode Exit fullscreen mode

3. OPERATORS IN JAVASCRIPT

Type Example Meaning
Arithmetic + - * / % Math operations
Assignment = += -= Assign values
Comparison == === != Compare values
Logical &&

Example:

let a = 10;
let b = 5;

console.log(a + b);   // 15
console.log(a > b);   // true
console.log(a == 10); // true
Enter fullscreen mode Exit fullscreen mode

4. CONDITIONAL STATEMENTS

Make decisions in your code.

if / else if / else

let age = 18;

if (age >= 18) {
  console.log("You are an adult.");
} else {
  console.log("You are a minor.");
}
Enter fullscreen mode Exit fullscreen mode

5. SWITCH STATEMENT

let day = "Monday";

switch(day) {
  case "Monday":
    console.log("Start of the week");
    break;
  case "Friday":
    console.log("Weekend loading...");
    break;
  default:
    console.log("Just another day");
}
Enter fullscreen mode Exit fullscreen mode

6. LOOPS IN JAVASCRIPT

Loops help us repeat tasks.

for loop

for(let i = 1; i <= 5; i++) {
  console.log(i);
}
Enter fullscreen mode Exit fullscreen mode

while loop

let i = 1;
while(i <= 5) {
  console.log(i);
  i++;
}
Enter fullscreen mode Exit fullscreen mode

7. FUNCTIONS IN JAVASCRIPT

Functions perform specific tasks.

Function Declaration

function greet() {
  console.log("Hello World");
}

greet();
Enter fullscreen mode Exit fullscreen mode

Function with Parameters

function add(a, b) {
  return a + b;
}

console.log(add(5, 3));  // 8
Enter fullscreen mode Exit fullscreen mode

8. ARRAYS IN JAVASCRIPT

Arrays store multiple values in one variable.

let fruits = ["Mango", "Banana", "Apple"];

console.log(fruits[0]);  // Mango
Enter fullscreen mode Exit fullscreen mode

Array Methods

fruits.push("Orange");   // Add item
fruits.pop();            // Remove last item
console.log(fruits.length); // Count items
Enter fullscreen mode Exit fullscreen mode

9. OBJECTS IN JAVASCRIPT

Objects store data in key-value pairs.

let person = {
  name: "Dhanian",
  age: 25,
  country: "Kenya"
};

console.log(person.name);  // Dhanian
Enter fullscreen mode Exit fullscreen mode

10. JAVASCRIPT OUTPUT METHODS

Method Usage
console.log() Output to console
alert() Popup alert box
document.write() Write to HTML

EXTRA RESOURCE FOR YOU!

Get the Complete JavaScript Ebook

For Beginners to Advanced → With Code Examples & Projects!

👉 Grab your copy here:

https://codewithdhanian.gumroad.com/l/jjpifd


Conclusion

Congrats on completing Day 2 of your JavaScript journey!

Today you learned:

  • Variables
  • Data Types
  • Operators
  • Conditions
  • Loops
  • Functions
  • Arrays
  • Objects
  • Output methods

Top comments (1)

Collapse
 
hafiz_abdullah_c4f93578 profile image
Hafiz Abdullah

Nice work