Pages

Thursday, March 28, 2019

Javascript ASCII code to character and vice versa

For capital letter,

65 = A
66 = B
...
89 = Y
90 = Z

String.fromCharCode(An integer); 
e.g. 
String.fromCharCode(66) will return B
String.fromCharCode(105) will return i (lower case i )

For small letter,

a = 97
b = 98
...
z = 122

'a'.charCodeAt(0) will return 97
'cdef'.charCodeAt(3) will return 102

Thursday, March 14, 2019

Javascript for/in for/of forEach and for(;;)

Javascript has different variants of iteration with different feature. Below is a summary of different for loop iteration with their features:



For /in
For / of
Obj.forEach
Traditional for
Object Key type
All (numeric + non-numeric)
Numeric only
Numeric only
Numeric only
Index vs Value
Index only
Value only

To get index Array#entries()
Index + Value 

Index as the second param of callback fn
Index only
Empty element
const arr = ['a',, 'c'];

Ignore empty element
Consider empty element
Ignore empty element
Consider empty element
Function Context (context of this )
this of the outer context
this of the outer context
Own version of
this
this of the outer context
Async / Await + Generator

Yes
Y
With caveats and not straight forward
Y

Side topics emerged here:
Ø  ESLint
Ø  Generator
Ø  Yield
Ø  Async / Await

Source and Details: here