Damar Paramartha
Damar Paramartha's Blog

Damar Paramartha's Blog

I'd tell my past self to choose Typescript as the first language for programming

I'd tell my past self to choose Typescript as the first language for programming

Damar Paramartha's photo
Damar Paramartha
·Sep 23, 2022·
Play this article

Table of contents

  • The Why
  • To me, in the past

The Why

Typescript is a superset of Javascript (just another programming language) that you can use everywhere, such as web, mobile, desktop, or IoT. Typescript won't run if your program has errors. At the end of the day, it's just a language to talk to on your computer.

To me, in the past

So, where should we start? Here → typescriptlang.org/play. No download and setup are required. Just focus on learning the basics.

Writing your first line of code

First, you'll learn how to show something to the screen by writing specific syntax in the editor.

console.log("Hello World")

Run the code by clicking the button Run or ctrl + enter or ⌘ + return (if you are on Mac). The code is pretty self-explanatory. Now replace it with these new lines.

const name: string = "Damar"
console.log("Hello " + name)

I think you get the idea it's not that hard to understand. Are you getting excited with just two lines above? Don't get too excited because things will get extremely hard. You might not understand what const or string is right now, but you could learn it fast, and the most important thing you need is discipline.

image.png

For a quick explanation

string is just how you tell the computer it is a type of single or multiple characters, so you use it for a word or sentence. const is how you tell the computer it's a constant variable. You cannot change it later. For that, you can use let.

let name: string = "Damar"
let newName: string = "Sam"

name = newName
console.log(name) // This will return "Sam"

Tips: Use // to write comments on your code. The computer will ignore it.

What else is in there for type annotations?

Besides string, there are many of them, such as number, boolean, and array. Try to open the language documentation. I know you will open that URL and find that it's too long to read and not ready to learn with words you don't understand and prefer the dumbed version of it in this article. It's okay for now.

Condition

The next important thing in programming is understanding conditions.

/*
  if (<conditions>) {
    <statement>
  } else if (<another conditions>){
    <another statement>
  } else {
    <another statement>
  }
*/

let age: number = 18
let isAdult: boolean = false
if (age >= 18){
  isAdult = true
}
console.log(isAdult) // This will return true

Scope of code

This is where it gets interesting. Let me introduce you to the term function. Simply it's a grouping method of your code with curly brackets { }. You can write it with function and the function name (whatever you want).

function introduction(){
  const name: string = "Damar"
  let age: number = 22
  console.log("My name is " + name + " and I'm " + age + " years old")
}
introduction()
introduction()

You can only access variables within your function. So if you do console.log(age) outside the { }, you will get an error. You can tell the computer to do things multiple times by writing multiple functions. In this case, the twice introduction()

Function need an input

function add(a: number, b: number){
  console.log(a + b)
}
times (2, 3) // return 5

Function must return value

function times(a: number, b: number): number{
  return a * b
}
times(2, 3) // return 6

What's next?

I know you just need a keyword to search for what you need. Let me list it for you.

  1. Big O Notation
  2. Data Structure
  3. Algorithm

You will fall into the pit of competitive programming. You like to solve algorithm problems but don't want to admit it because of your lack of skills. Learn from others via youtube videos, blog posts, or mentors. After many years, you'll see the pattern of each problem, and you can solve it quickly.

Stop

It would help if you rethought the choice of your life. Do you want to write code forever? Maybe just because your university major is computer science and you did not want to waste that, or do you really enjoy it?

 
Share this