DEV Community

Cover image for Javascript Questions
Esraa Refaat
Esraa Refaat

Posted on

1

Javascript Questions

Is this a pure function?

function sum(a, b) {
return a + b;
}

A: Yes
B: No

Answer: A

A pure function is a function that always returns the same result, if the same arguments are passed.

The sum function always returns the same result. If we pass 1 and 2, it will always return 3 without side effects. If we pass 5 and 10, it will always return 15, and so on. This is the definition of a pure function.

Top comments (0)

Some comments have been hidden by the post's author - find out more

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay