Data Types, Variables, Functions, Return, Arguments/Parameters, Function Calling & Concatenation.
- Data Types - Number, String, Boolean, Undefined, Null, Symbol, BigInt.
Number - Numeric values (integers, floats) - let age = 25;
String - Text data - let name = "John";
Boolean - True or False - let isOnline = true;
Undefined - A variable declared but not assigned a value -let x;
Null - Represents an intentional "no value"- let data = null;
Symbol - Unique and immutable value - let id = Symbol("id");
BigInt - For very large numbers - let big = 12345678901234567890n;
- Variables
var Old way (not recommended now) ✅ Yes
let Modern way (use for values that may change) ✅ Yes
const Use for fixed values (won’t change) ❌ No
- Using let let age = 25; age = 26; // ✅ Can change
2.Using const
const pi = 3.14;
// pi = 3.14159; ❌ Error: Cannot reassign a const variable
3.Using var (old style)
var name = "Alice";
name = "Bob";
What is a Function in JavaScript?
A function is a block of code designed to perform a task.
You can reuse it whenever needed.
👉 Think of it as a machine that does a specific job when called.
Syntax:
function functionName(parameters) {
// code to execute
}
✅ functionName – name of the function
✅ parameters – values you pass to the function (optional)
✅ Simple Example:
function greet() {
console.log("Hello, welcome!");
}
greet(); // Calling the function
- Function with Parameters
function greetUser(name) {
console.log("Hello, " + name + "!");
}
greetUser("Jeevananthan"); // Output: Hello, Jeevananthan!
- Function that Returns a Value
function add(a, b) {
return a + b;
}
let result = add(5, 3);
console.log(result); // 8
🔶 What is concatenation?
Concatenation means joining two or more strings together.
🔹 Using + Operator (Most Common Way)
let firstName = "Jeevananthan";
let lastName = "Annadurai";
let fullName = firstName + " " + lastName;
console.log(fullName); // Jeevananthan Annadurai
✅ " " (space in quotes) is added between names for spacing.
🔹 Concatenating with Numbers
JavaScript converts numbers to strings when using + with text:
let age = 25;
let text = "I am " + age + " years old.";
console.log(text); // I am 25 years old.
Quick Summary
✅ 1. Data Types
JavaScript has:
Primitive types like string, number, boolean, null, undefined, symbol, and bigint
Non-primitive types like object, array, and function.
✅ 2. Variables
Use let for values that can change.
Use const for values that shouldn’t change.
Avoid var unless you're dealing with older code.
✅ 3. Functions
Functions are reusable blocks of code.
Use parameters to pass data in.
Use return to send a result back.
Arrow functions (=>) make your code shorter and modern.
✅ 4. Concatenation
Used to join strings together.
Use + or += for basic joining.
Use template literals (Hello, ${name}
) for cleaner, more readable code.
Thank you for reading my blog. Let's get connected if you have any questions regarding these topics. Have a good day!! Bye see ya...
Top comments (0)