Is the Arrow function of es6 the same as the normal function?

Asked 2 years ago, Updated 2 years ago, 59 views

const Message=props=>div>{props.msg}</div>

and

function Message(props){
    return(
        <div>{props.msg}</div>
        )
}

Is the same?

Can I check somewhere?

javascript es6

2022-09-30 19:37

1 Answers

No, it's not.

Functions defined by a normal function definition can be called in new, but not an Arrow function.

var Foo=function(){};
var foo=new Foo();//OK 

var Foo=()=>{};
var foo=new Foo();// Error  

Also, although it does not appear in this example, there is a difference in the treatment of this between the normal function and the Arrow functions.
For more information, see "Arrow function vs function declaration/expression: Are they equivalent/exchangeable?" and in your home Q&A.

(This kind of problem seems to come out well if you search for 〇 v vs ×× in English.)Also, in the end, it would be better to read the specifications.)


2022-09-30 19:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.