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
const
is used when we don't want to reassign a value, whilelet
allows 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)