Code Structure
- expr, stmt
;
.. & blocks{..}
.. - comment: inline / mtp-line .., javadoc/JSDoc ..
- Coding style & linters ..
Variable
A named storage in memory for data
<type>
: allowed value, ops & memory used, e.g. primitive / reference type- static/dynamic typing: compile/runtime type checking
<name>
: descriptive ref of value (no keyword, UPPERCASE_CONST)<value>
: literal / referencenull
literal: obj unavailable marker (instanceof
=> false)
- var scope & var shadow
Char
Operator
- comparison & equality check ops => bool
- conditional op
?..:
, logical ops! && ||
- bitwise/bit shift ops .., op precedence & op return
Control flow
if..else
,switch
(block falls througth 贯穿 ==> case group)switch/case
arg: in JS, can be any expr, value compare===
; working types in Java
while
&do..while
,for
&for..of
(JS) &for..:
(Java)break
/continue
(non-expr in JS, not in?..
) & label
Function
Fn basics ..
- fn naming …
- fn-param: declare in fn(..) & init when fn-call by args
- pass args to fn: copy value to fn-params (use as a local var in fn-body, change not seen outside, default value)
- pass method to fn: callback fn, lambda expr
- rest param:
fn(.., ...arr)
&method(.., int... arr)
- local var “shadow” outer var, global var
- return: default return
undefined
/null
,(...)
for mtp-line value
Array
arr.length
,arr[i]
186****5678
:fill(..)
String
- immutable, concat op
+
- get info:
charAt(i)
,indexOf()
,starts/endsWith()
,contains()
; - modify:
replace()
,split()
,substr()
, rm space:trim()
,replaceAll("\\s", "")
Obj-oriented
- OOP 3大基本特性: 封装,继承,多态 (一种定义,多种实现)
Class
class & obj: prototype & instance
class member: field (value of state) & method (implementation of behavior), nested type;
constructor &
new
op,obj.<member>
;this(..)
&this.<member>
;static
method: no access to instance members, nothis
Enum: a fixed set of consts
Inheritance
extends
,super
; method/constructor & fields override- call
super(..)
in child.con(): super()
called implicitly (Object has a empty con()), callsuper(..)
explicitly [p159]instanceof
op
GC: manually drop ref by null
Refs
- Oracle Java Tut & Javase 8 API
- 《Java 从入门到精通》(项目案例版) 2017.9
- javascript.info