L04_JS_TS
L04.1_Intro
- created and linked hello world in js
- in typescript: need json file: tsc --init / shift strg b
EIA2
Einblick
- v=v+1: adds 1 to v and saves value in v
- =: first right side, saves in left side
Variablen
- variables are... variable
- variable needs to be declared first -> let v=1
- definition of a variable -> for example v=v+1
Datentypen
- explicit annotation of datatypes: let/const name: type = value;
Primitive Datentypen
- in ts/js: number, string, boolean
JS vs TS
- ts pro: improved error checking, IDE support for code hinting and completion, and compatibility with newer ECMAScript features
- ts con: steeper learning curve, additional compilation steps, potential overreliance on its compiler for error detection
- source
Operators
Arithmetic operators
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Exponentation (**)
- Division (/)
- Modulus/Division Remainder (%)
- Increment (++)
- Decrement (--)
Assignment operators
- =
- += (the same as x=x+y)
- -=
- *=
- /=
- %=
- **=
Comparision operators
- Equal to (==)
- equal value and equal type (===)
- not equal (!=)
- not equal value or not equal type (!==)
- greater than (>)
- less than (<)
- greater than or equal to (>=)
- less than or equal to (<=)
- ternary operator (?) -> let voteable = (age < 18) ? "Too young":"Old enough";
Logical operators
- logical and (&&)
- logical or (||)
- logical not (!)
Type operators
- returns type of a variable (typeof)
- returns true if an object is an instance of an object type (instanceof)
Bitwise operators
- AND (&)
- OR (|)
- NOT (~)
- XOR (^)
- left shift (<<)
- right shift (>>)
- unsigned right shift (>>>)
Arrays
Objects