DEV Community

Anandhi P
Anandhi P

Posted on

Objects and Functions in JavaScript

Object

  • An object in JavaScript is used to store related data and information in one place.

    • An object stores data using key and value pairs.

Example:

let student = {
name: "Anandhi",
age: 21,
course: "Computer Science"
};

console.log(student.name);

Output:

Anandhi

Function

  • A function is a block of code used to perform a specific task.

  • We can create a function once and use it many times.

Example:

function greet() {
console.log("Hello");
}

greet();

OutputL:

Hello

Simple Difference :

  • Object → Stores data.

  • Function → Performs a task.

Top comments (0)