day 09 of 1000 days of code
Welcome, I hope you are doing well in life.
Typescript- type simply means data types. It is an extension of javascript, like a pre-processor. In the end, it will be compiled to javascript only and add checks to it. The reason for introducing it was javascript engine tries to run over code at any cost, it used type coercion and convert the values. This results in giving values which we may not want, eg 2+"2" > "22", null*2 > 0 etc.
It does static checking and gives hints for errors before runtime. Javascript doesn't have this feature, we have to use the extension in ide for that.
let test: string = "this is a string";
// variableName:type
The main types are string, number, and boolean. There is also :any type, which is rarely used, if assigned it is just like js let. Typescript uses type inference, ie automatically assigns the type when we assign value to the variable. For function, it is assigned as below. There are two more types of functions :void which means null/undefined like when we use guard clause [if(condition) return;] and :never , in this function never returns a value eg when we throw an error or when we run game loop(eg using requestAnimationframe).
const fName=fucntion(parameter1:string="default value"):number{
//func(parameter:typeOfParameter):returnType
}
Function fName2(parameter1:string="default value"):number{}
//for functions without name, like we use in map, filter it infer the type
other: I am making sudoku solver project. I used CSS grid to make the rows and columns. I'm stuck on one logic though, probably the project will be completed by tomorrow. I am also beautifying the snake game project. To add automatic movement of snake I used requestanimationframe function. I also have to limit the rate at which it was being called. I used a variable and if statement for that. Just increase its value and call function after a condition+reset variable value and keep on adding 1 to snake movement.
For tomorrow I will also learn git as I want to record my projects from now on.
Personal: I deleted the Instagram app and other distractions. Actually, I deleted them earlier also but as I was on bed rest I installed them. Now deleted them again. I used to play lots of games and waste time on the phone, it's hard to stop it suddenly(hope you guys will understand). Also, I will have to fight this procrastination thing, much time is wasted on that also.