JavaScript
Variables
please use let
over var
var
- function scope
- use before declaration
- mutable
let
- block scope
- use after declaration
- mutable
const
a
const
means the reference is protected from reassignment. The value is not immutable though and can change, especially if it’s a complex construct like an object.
Data Type
There are 6 primitive data types: string, number, bigint, boolean, undefined, and symbol
JavaScript is weak type, variables get their type according to the value
typeof
and instanceof
will be super useful
1 | function show(arg){ |
1 | //template string |
Functions
In JavaScript, functions are actually objects
FOP
Just like Python, you can pass functions as parameters
1 | function f(){ |
Anonymous functions
1 | // f = lambda x : x ** 2 |
Control Flow
please always use ===
instead of ==
Similar to C
1 | let statcode = 400 |
Array
In JavaScript, arrays are also Objects(like Python).
One major benefit of arrays is that you can store different types of data in one array.
1 | > let arr = [] |
Loop
while
and for
are again same with C. And we also have Python’s flavor added in
1 | let array = [1,2,3,4,5] |