Do you wanna learn JavaScript within three days?

Beginners guide

Sivarajah Sarangani
3 min readFeb 22, 2021

JavaScript is the basic for developing web pages rather than HTML & CSS. It is used mainly for enhancing the interaction of a user with the webpage. In other words, you can make your webpage more lively and interactive, with the help of JavaScript.

This is a scripting language as it cannot be run on its own and need a help of browser.

You should place all your JavaScript code within <script> tags (<script> and </script>) if you are keeping your JavaScript code within the HTML document itself.

Write your first program:

Hello world example

Declaration of variables in JS

Different ways of declaration

var can be used whole over the program. let can be used within the scope where we needed. const cannot be changed through the whole program.

This is a simple program done by declaring variables. So the output will be like this..

How to use conditional statements

Conditional statements are used to decide the flow of execution based on different conditions. If a condition is true, you can perform one action and if the condition is false, you can perform another action.

There are mainly three types of conditional statements in JavaScript.

  1. If statement
  2. If…Else statement
  3. If…Else If…Else statement

If statement

Syntax

This can be used to check only specific condition.

Figure1.1

To check, if the person is adult or not, we can use if statement. And the output will be:

Output1 of figure 1.1
Output2 of figure1.1

If…Else statement

Syntax

If you have to check two conditions and execute a different set of codes you can use this.

The output will determine by the compiling time of user.

If.. Else If.. Else statements

You can use If….Else If….Else statement if you want to check more than two conditions.

Figure1.2

User input will determine the output of the program.

Output of figure1.2

Conclusion

Here we learn how to code by declaring variables, and how to use the conditional statements according to our necessity. In my next blog you can find how to use loops and arrays.

--

--

Sivarajah Sarangani

Faculty of Information Technology- University of Moratuwa