Introduction to Javascript Language.

Olasunkanmi-Ojo Fatima
CodebagNG
Published in
3 min readNov 27, 2017

After working with HTML5, CSS and Bootstrap to replicate various mock-up as a beginner, I moved to javascript language which is the programming language of HTML and WEB. This article is written based on what I was able to learn as a javascript beginner.

Javascript is used to make webpages interactive, create games, validate input values of a web form.

Javascript as a programming languages also has set of rules which are:

1.JavaScript statements are separated by semicolons.

2.Javascript statement are composed of Values, Operators, Expressions, Keywords, and Comments.

3.For javascript names or identifiers, Numbers are not allowed as the first character.

4.All JavaScript identifiers are case sensitive.

5. Hyphens are not allowed in JavaScript. It is reserved for subtractions.

Creating the first Javascript:

Javascript code is inserted between <script> and </script> tags. Javascript can be created or added to webpage internally or externally. To add Javascript to webpage internally, place the <script> tag in the <body> or <head> sections as shown below:

Placing the <script> tag in the <body> section:

<html><head><title></title></head><body><script type=”text/javascript”>
</script></body></html>

Placing the <script> tag in the <head> section:

<html><head><title></title><script type=”text/javascript”>
</script></head><body></body></html>

To add Javascript to webpage externally; after typing the script and saving with name.js on a separate page of the editor, it is then linked to the index page using <script> tag as shown below:

Typing and saving with name.js on a separate editor:

name.js

var myNum1 = 5;var myNum2 = 4;if(myNum1 > myNum2){alert(“javascript is easy to learn”);}

linking to index page:

<html><head><title></title><script src=”name.js”></script></head><body></body></html

The basis for Conditional statements:

Conditional statements are used to perform different actions for different decisions. The various types of conditional statements used are: if statement, else statement, else if statement and switch statement. Below are the conditional statements that I studied and would like to share.

The if statement syntax:

if(condition){statements}

Statements will be executed only if the specified condition is true.

Example:

var myNum1 = 5;var myNum2 = 4;if(myNum1 > myNum2){alert(“javascript is easy to learn”);}

The else statement:

if(expression){block of code to be executed if the condition is true}else{block of code to be executed if the condition is false}

Example:

var myNum1 = 5;var myNum2 = 4;if(myNum1 > myNum2){alert(“javascript is easy to learn”);}else{alert(“javascript is a scripting language”)}

The else if statement:

else if statement is used to specify a new condition if the first condition is false.

if (condition1)
{
block of code to be executed if condition1 is true
} else if (condition2) {
block of code to be executed if the condition1 is false and

condition2 is true
} else { block of code to be executed if the condition1 is false and condition2 is false
}

Example:

var course = Englishif (course == English) {
document.write(“HTML tutorial”);
} else if (course == Science) {
document.write(“CSS tutorial”);
} else {
document.write(“Javascript tutorial”);
}

The Switch statement:

In other to test for multiple conditions, switch statement can be used instead of writing multiple conditions with if else statements.Switch expression is evaluated once. The value of the expression is compared with the values of each case. If there is a match, the associated block of code is executed.

Syntax for switch statement:

switch(expression) {
case n1:
statements
break;
case n2:
statements
break;
default:
statements
}

Example:

Var day = 2;switch(day) {
case 1:
document.write(“Monday”);
break;
case 2:
document.write(“Tuesday”);
break;
default:
document.write(“Another day”);
}

Break keyword stops execution of more code and case testing inside the block.

Default keyword specifies the code to run if there is no case match.

This is how far I can go for now. As I continue with my learning process, I will also share more on introduction to Javascript. Thank you very much.

--

--

Olasunkanmi-Ojo Fatima
CodebagNG

Product | Women-In-Tech | Community Program Manager| Love to explore and travel | Open to greater opportunities