All I Know About Javascript

Almayra
5 min readFeb 13, 2020

On the first day I learn Javascript, my lecturer said coding is like cutting a paper. Some people cut it with scissors and some with a cutter. Different tools with the same outcome. How so? I guess that’s because coding asked us to solve a problem trough logic skills which depend on how the way we think and it’s kind of challenging for me as I never use logic to solve mine. But it’s okay. I once said that I’m willing to face the difficulty of a problem to help everyone’s life easier so I have to keep my words.

In these five days of learning Javascript, there are some concepts that you better understand it first before you go further. We called it Javascript fundamental. It is for a beginner like us. Okay, so… the first thing you should do is to download the text editor software to develop your coding. After that, you can open a new folder and create an HTML or js file.

In Javascript fundamental, there are variables. Variables (or var for shorten) are known for something to contain your data values. You can name it whatever you want. Javascript variables can hold many data such as strings, numbers, boolean (true/false) and more.

After that, Javascript can display data in a different ways like console.log( ), alert( ), document.write( ) and innerHTML. Are you wondering when to use them? Let me simplify it for you.

When you want to write into an HTML element, you can use innerHTML.

When you want to write the HTML output, try using document.write( )

When you want to notify something to the user, use alert( )

When you want to write into the browser console, try using console.log( )

Then, there are 3 types of dialog boxes. Alert is one of them. So.. what is a dialog box?

A dialog box is a type of window that is used to enable communication and interaction between a user and a software program.

What is it like? And what are they?

This Is Alert Box
This is Prompt Box
This is Confirm Box

Can you tell the difference? I hope this is still easy for you to understand because henceforward it will be a little more complicated. But don’t worry cause we are all learning here. It’s fine to struggle at first.

Next, there are 6 types of operators. The operator is a symbol to tells the compiler to perform specific mathematical and logic functions.

  1. Arithmetic Operators = Operators to do the arithmetic operations
Arithmetic Operators

What’s the difference between addition with increment and subtraction with decrement?

Increment only increase one number from the previous number, and so does the decrement. It only decreases one number from before. Are you getting it so far?

2. Comparison Operators = Operators for comparing 2 values to produce a boolean

Comparison Operators

The difference between equality and identity are data types. Equality can compare 2 values even when the types of its data are different, while identity can not.

3. Logical Operators = These operators are typically used with 2 booleans (logical) values

Logical Operators

example :

Next is the conditional statement. The conditional statement is used to perform different actions based on different situations. In Javascript we have the following elements :

1. If = to specify a block of code to be executed, if a specified condition is true

2. Else = to specify a block of code to be executed, if the same condition is false

3. Else if = to specify a new condition to test, if the first condition is false

4. Switch = to specify many alternative blocks of code to be executed

example :

If the user puts the value below 12 like this:

The outcome will be like this:

And if the user puts the value above 12:

The outcome will be this:

It’s exciting, right?

Okay, let’s move to loop material, this is a bit complicated one. But with a lot of practice, I’m sure you can master it later. For your coding skill improvement, I suggest you play code wars or HackerRank. It will help you to increase your skills.

Looping is divided into 2 types: Counted loop, and uncounted loop.

1. Counted Loop is a definite loop and has determined in length.

2. Uncounted Loop is a loop that is unclear how many times must repeat until it finds the goal.

For is a counted loop because it’s clear how many times you have to repeat. While is an uncounted loop because the while loops run the code block in the specified condition correctly. Do while is the same as while, but the difference is do while checks the condition behind (after repeating) and while loops checking the condition from the very first beginning (before repeating).

This is an example for For :

and it will turn out like this :

So, among Javascript fundamental, which one are you familiar to?

--

--

Almayra

an idealist who loves to write code and phrase on things I found interesting to talk about