2024-05-06 20:40:05 +00:00
|
|
|
---
|
2024-10-30 17:34:11 +00:00
|
|
|
date: 2020-10-06
|
2024-05-06 20:40:05 +00:00
|
|
|
id: 2b93c1c4-b0ed-4b03-846b-557ccc9d6080
|
|
|
|
title: JavaScript declaration notation
|
|
|
|
---
|
|
|
|
|
|
|
|
There is a shorter way to declare functions:
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
function square(x) {
|
|
|
|
return x * x
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(square(5))
|
|
|
|
```
|
|
|
|
|
|
|
|
Function declarations are not part of the regular top-to-bottom flow on
|
|
|
|
control. They are conceptually moved to the top of their scope and can
|
|
|
|
be used by all the code in that scope.
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
console.log("The future says:", future())
|
|
|
|
|
|
|
|
function future() {
|
|
|
|
return "Where are my flying cars?"
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|