2.1 JavaScript Basics – The Language of the Web

Table of Contents

Hey little coder! šŸ‘‹ I’m Vikas Sankhla, your tech buddy from Web Codder. Today, we’re going to explore JavaScript – the magic language that makes web pages come alive! āœØšŸ§‘ā€šŸ’»


šŸš€ What is JavaScript?

JavaScript is the brain of a website. 🧠

It helps you make things move, pop up, slide, or react when someone clicks a button.

Without it, a webpage would be like a photo – pretty but boring. šŸ˜…

Javascript For Python Developers Watermarked
2.1 Javascript Basics – The Language Of The Web 4

šŸ”¤ Variables – The Boxes That Store Stuff

Think of variables as boxes where we can store different kinds of data.

šŸ“¦ Example:

let name = "Vikas";
let age = 21;
let isCool = true;

Here we created three boxes: one for a string, a number, and a boolean. šŸ‘

šŸ“˜ Data Types:

TypeExample
String“Hello”
Number25, 3.14
Booleantrue, false
Array[1, 2, 3]
Object{name: “Vikas”}
Nullnull
Undefinedundefined

🧾 Declaring Variables: var, let, and const

  • var – Old way. Can be buggy if not careful. 😬
  • let – Modern and safe. Use it for values that change.
  • const – Use when the value should NOT change.

🧪 Example:

var score = 100;  // can be updated
let user = "Ravi"; // can be updated
const pi = 3.14;   // can’t be updated

šŸŒ Scope – Where Can You Use Your Variable?

Scope tells us where a variable can be used.

šŸ—‚ļø Types of Scope:

  • Global Scope – Outside everything. Available everywhere.
  • Local Scope – Inside a function.
  • Block Scope – Inside { }, like loops or if blocks.

šŸ” Example:

let name = "Vikas"; // global

function greet() {
  let message = "Hello"; // local
  console.log(message + name);
}

if (true) {
  let mood = "Happy"; // block
}
Variable Scope Visualization
2.1 Javascript Basics – The Language Of The Web 5

šŸ§™ā€ā™‚ļø Hoisting – JavaScript’s Magic Trick

JavaScript moves var declarations to the top of the file before running. šŸŽ©āœØ

But it doesn’t do that with let or const.

āš ļø Example:

console.log(a); // undefined
var a = 5;

console.log(b); // Error āŒ
let b = 10;

āž• Operators – Do Math and More

JavaScript has many operators to do stuff.

🧮 Basic Operators:

TypeSymbolExample
Addition+5 + 3 = 8
Subtraction7 – 2 = 5
Multiplication*4 * 3 = 12
Division/10 / 2 = 5
Modulus%9 % 2 = 1
Assignment=let x = 5
Comparison==, ===x === 5

šŸ” Control Flow – Making Decisions

Sometimes, your code needs to make choices.

āœ… If-Else:

let age = 18;
if (age >= 18) {
  console.log("You can vote");
} else {
  console.log("Too young to vote");
}

šŸ”„ Else-If:

let score = 70;
if (score > 90) {
  console.log("A Grade");
} else if (score > 60) {
  console.log("B Grade");
} else {
  console.log("Try again!");
}

šŸ”€ Switch:

let fruit = "apple";
switch (fruit) {
  case "apple":
    console.log("Red fruit");
    break;
  case "banana":
    console.log("Yellow fruit");
    break;
  default:
    console.log("Unknown fruit");
}

⚔ Ternary Operator:

let isLoggedIn = true;
let message = isLoggedIn ? "Welcome!" : "Please log in.";
console.log(message);
Lejs 0402
2.1 Javascript Basics – The Language Of The Web 6

šŸ“š Recap Table

ConceptUse
VariableStore values
Data TypesDifferent kinds of data
var/let/constDeclare variables
ScopeWhere a variable works
HoistingMoves var to the top
OperatorsDo math & compare
ConditionalsMake decisions

šŸ“Œ Conclusion

Now you know how JavaScript helps you talk to the web like a superhero! šŸ¦øā€ā™‚ļøšŸ’»

Keep practicing with small examples.

You’ll be building awesome interactive websites in no time! šŸš€

šŸ”” Subscribe for more: YouTube/Web Codder
šŸ“š Learn more here: WebCodder Automation
šŸ’¬ Join our chat: WhatsApp Community

See you in the next adventure! šŸ§‘ā€šŸ’»šŸŒ

Share the Post:
Picture of Web Codder

Web Codder

Vikas Sankhla is a seasoned Full Stack Developer with over 7 years of experience in web development. He is the founder of Web Codder, a platform dedicated to providing comprehensive web development tutorials and resources. Vikas specializes in the MERN stack (MongoDB, Express.js, React.js, Node.js) and has been instrumental in mentoring aspiring developers through his online courses and content. His commitment to simplifying complex web technologies has made him a respected figure in the developer community.

Related Posts