JavaScript Basics: Data Types, Variables, Functions, and More
Today, I continued my JavaScript journey by diving into some of the core concepts that every developer needs to know. Here's a breakdown of what I learned and some examples that helped me understand things better
1. Data Types in JavaScript
JavaScript supports several basic data types:
- String – Text enclosed in quotes
let name = "Tamil";
- Number – Integers or floating-point numbers
let age = 25;
- Boolean – true or false
let isStudent = true;
- Undefined – A variable declared but not assigned
let score;
- Null – Intentionally empty
let result = null;
2. Variables
Variables are used to store data values. You can declare them using var, let, or const.
let city = "Coimbatore";
const country = "India";
I learned that
constis used when we don't want to reassign a value, whileletallows reassignment
3. Functions
Functions are blocks of reusable code. They help us avoid repeating code.
Function Declaration
function greet() {
console.log("Hello, World!");
}
Calling a Function
greet(); // Output: Hello, World!
4. Parameters and Return Values
Functions can take inputs (parameters) and return outputs using the return keyword.
function add(a, b) {
return a + b;
}
let sum = add(5, 10);
console.log(sum); // Output: 15
5. String Concatenation
Joining strings together is called concatenation.
let firstName = "Tamil";
let lastName = "Selvam";
let fullName = firstName + " " + lastName;
console.log(fullName); // Output: Tamil Selvam
I found it exciting to see how functions and variables work together to create dynamic outputs!
Final Thoughts
Learning these foundational concepts is like building blocks for my JavaScript journey. I feel more confident now in writing basic code and understanding how logic flows in a program . Tomorrow, I’ll be moving on to conditional statements and loops!
Thanks for reading! If you're also learning JavaScript, feel free to connect—we can grow together
Top comments (0)