JavaScript is one of the most popular and powerful programming languages used to create interactive websites and web applications.
Types of JavaScript
Variables
Functions
Concatenation
Return statements
Calling Functions
๐งฉ 1. Types in JavaScript
JavaScript supports several data types, which can be grouped into two categories:
๐น Primitive Types
These are the basic types:
String: Text. Example: "Hello"
Number: Numeric values. Example: 42, 3.14
Boolean: true or false
Null: A deliberate non-value
Undefined: A variable that has been declared but not assigned
Symbol: Unique values (advanced)
BigInt: Large integers (new in ES2020)
let name = "Sivasankari"; // String
let age = 23; // Number
let isStudent = true; // Boolean
let data = null; // Null
let value; // Undefined
๐ธ Non-Primitive Types
Object
Array
Function
let person = { name: "Sivasankari", age: 23 }; // Object
let colors = ["red", "blue", "green"]; // Array
๐งช 2. Variables in JavaScript
Variables store data values. In modern JavaScript, we use:
let: Block-scoped variable (preferred)
const: Block-scoped, constant value
var: Function-scoped (older and less recommended)
let city = "Coimbatore";
const country = "India";
๐ง 3. Functions in JavaScript
Functions are reusable blocks of code that perform a task. Here's how to declare and use them:
function greet() {
console.log("Hello, World!");
}
greet(); // Call the function
Parameters and Arguments
function greetUser(name) {
console.log("Hello, " + name + "!");
}
greetUser("Alice"); // Output: Hello, Alice!
๐ 4. Concatenation in JavaScript
Concatenation means combining strings.
Using + operator:
let firstName = "Siva";
let lastName = "Sankari";
let fullName = firstName + " " + lastName;
console.log(fullName); // Output: Siva Sankari
๐ 5. Return Statement
The return keyword gives back a result from a function.
function add(a, b) {
return a + b;
}
let sum = add(10, 5); // sum is 15
console.log(sum);
If you don't use return, the function will return undefined by default.
๐ 6. Calling Functions
Once a function is defined, you can call or invoke it by using its name followed by parentheses ().
function sayHello() {
console.log("Hello!");
}
sayHello(); // Output: Hello!
๐ Conclusion
JavaScript is a powerful language, but understanding these fundamentals โ types, variables, functions, return statements, concatenation, and function calls โ is a solid first step.
Top comments (0)