0
Is there any difference between using “const” and “function” for writing functions?
const square = (n) => n * n; function square(n) { return (n * n); } Both these statements seem to do the same thing. Is there any sort of differences between the two? (other than const being more compact)
2 Antworten
+ 2
Its use for me depends on the case and the context where the functions are being written, I hope this can clarify it:
http://exploringjs.com/es6/ch_arrow-functions.html
https://medium.freecodecamp.org/constant-confusion-why-i-still-use-javascript-function-statements-984ece0b72fd
+ 1
the first will only be available in that scope while the second will be global.
also the first also ensures that at any point in that scope..
variable square will always be a function..it cannot be reassigned to something else