DEV Community

siva sankari324
siva sankari324

Posted on

Learning JavaScript: Data Types, Functions ,Variables,Concatenation,Return

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
Enter fullscreen mode Exit fullscreen mode

๐Ÿงฉ 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)
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)