Skip to content

Documentation improvement: clarify function assignment behavior #3973

@sujayhegde23

Description

@sujayhegde23

I was reading the Function expressions section and noticed a wording choice that confused me a little.

The section mentions that we can "copy a function to another variable". Maybe the intention is to show that functions are values in JavaScript, the wording initially made me think that a new function was being created.

issue in the section -> url -> https://javascript.info/function-expressions
topic is "Function is a Value"

the example code was ->
function sayHi() { // (1) create
alert( "Hello" );
}

let func = sayHi; // (2) copy

func(); // Hello // (3) run the copy (it works)!
sayHi(); // Hello // this still works too (why wouldn't it)

My understanding is that func receives a reference to the same function object rather than creating an independent copy of the function itself.
There maybe a chance that i have misunderstood it , the copy could mean the reference is copied and a little context about reference would help even if it is included in the previous section.

This is not a major issue, but I thought a small clarification might help readers who are learning about values and references.

Thank you so much for the documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions