DEV Community

Saravanan Cn
Saravanan Cn

Posted on

Day 12: Learning Anonymous Functions, Arrow Functions & Key-Value Pairs 🚀

Today is Day 12 of my web development learning journey.

I continued learning javascript about anonymous functions,arrow functions and key-value pair.

1.Anonymous Function

It is a function without a name.
`
let greet = function() {
console.log("Hello!");
};

greet();`

2.Arrow Function

An arrow function is another way to write a function using the => syntax.

Arrow functions can make function syntax shorter and easier to write.

`let greet = () => {
console.log("Hello!");
};

greet();

3.Key-Value Pair

I also learned about key-value pairs in Javascript Objects.

let student = {
name: "Saravanan",
age: 33,
course: "JavaScript"
};
`

Key-value pairs are used to store related information inside an object.

Top comments (1)

Collapse
 
jonrandy profile image
Jon Randy 🎖️ •

The function stored in the greet variable in your example is NOT anonymous. The act of assigning an anonymous function to a variable also gives the function the name of the that variable. This can be confirmed by checking the name property of the function, which will be 'greet' in your example.

True anonymous functions have no name.