Middle
Is console.log inside a function a side effect?
sobes.tech AI
Answer from AI
Yes, console.log inside a function is a side effect because it changes the external environment — it outputs data to the console, which affects the outside world of the program.
A side effect is any action of a function that goes beyond returning a value, for example:
- modifying global variables
- input/output (logging, network operations, file system)
- changing UI state
Example:
function greet(name) {
console.log(`Hello, ${name}!`); // side effect
return `Hello, ${name}!`;
}
Here, console.log is a side effect, and the returned value is a pure result.