# what is javascript? III
## object
1. object
```javascript=
let hero = {
n: "k",
a: 18,
"my-student":"123"
}
console.log(hero['my-student']) //123
console.log(hero.n) //k
console.log(hero.my-student) //error
```
2. Lexical Scope
x is what ? ans: there
```javascript=
var x = "there"
function a(){
console.log(x)
}
function b(){
var x = "here"
a()
}
b()
```
3. statement vs expression / arrow
```javascript=
//function statement
function x(){
}
//function expression
const x = function(){}
//arrow
const y = ()=>{}
```
4. function of first-class citizen
A programming language is said to have First-class functions when functions in that language are treated like any other variable. For example, in such a language, a function can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable.
https://developer.mozilla.org/zh-TW/docs/Glossary/First-class_Function
5. higher-order function
A higher order function is a function that takes a function as an argument, or returns a function. Higher order function is in contrast to first order functions, which don’t take a function as an argument or return a function as output.
```javascript=
function x(){
function y(str){
console.log("y" + str)
}
return y //回傳y方法
}
```
```javascript=
let res = x()
res(123) // y123
function x(){
function y(str){
console.log('hi')
}
return y() //回傳已執行y方法
}
let res = x() //hi
```
6. callback funciton(回呼函數)
```javascript=
function bye (callback)
{
if(typeof callback === 'function') //防呆機制
{
callback()
}
}
const cal = ()=>{ console.log('call') }
bye(cal) // a callback
let x = 3
bye(x)
```
7. Stack and Queue
https://www.youtube.com/watch?v=8aGhZQkoFbQ
ASI (Automatic Semicolon Insertion)
```javascript=
function A(){
}
```
###### tags: `JavaScript`