Operator
arithmetic operators: baiscly like python but include ++ and -- like the ones in c++. "+=" shortcut like this is also applicable.
comparision operator:
>,>=,.....
use === as strict equality operator.会同时比较类型和值 ”==“只比较值(会把右边的转换成左边的type如console.log(true=1))
ternary operator
python usually do below:
logical operator:
and:&&
or:||
not:!
bitwise or : |
Arrays and function:
array adding element
Finding elements: (primitive types) i.e. === , if it's reference type, reference will be checked, so we can't use this method.
indexOf: if not exist, return -1, the 2 of (1,2) means starting position
reference type:
we use array.find() method array.findIndex() to get the index
function is running through every elements of the array1 untill find the matched one.
Object:
as shown above, javascript may return a trusy value instead of boolean!
possible usage:
if customer choose a color , it will use the one chosen by customer otherwise will use the default one.
defining a object example:
factory functions:
跟constructor差不多
radius 等价于 radius: radius
draw: function(){...}=draw(){}
constructor:
new operator首先创造一个空对象,然后用这个this指针指向这个空对象,add features dynamicly and then return it .
adding and removing properties of the object:
although it is const circle, it means circle can't be assigned again, but we can still modify its features.
reference types and primitive types:
函数也是对象:
如下图例子, function circle(radius)其实是调用了new Function这个constructor
for..of is only applicable to thingies that is iterable, such as arrays and maps
we may use Object.keys(object) or Object.entries(object) which returns a array of strings
clone object using Object.assign() or spread operator
garbage collector system
unlike C/c++ in which we need to do garbage collection manual. Javascript has complex algorithm running under the scene to recycle unused garbage
Built-in object
Math
String:
it is a primitive , but javascript engine will transform it to an object if we call method
template literals:
To format strings in a more elegant way
Date: