JavaScript Introduction

JavaScript Introduction

Chapter 4 with examples

Hello everyone, My name is Arinze Calistus. The purpose of this blog is to teach you all you need to know about JavaScript/Programming.

JavaScript Statements

JS programs consist of statements with appropriate syntax. A single JS statement may span a single or multiple lines. JS statements should also be ended or separated by semicolons ;.

Below is an example of a single-line statement. This statement writes the text "Hello World!" to the paragraph element with the demo id.

document.getElementById("demo").innerHTML="Hello World!"

Below is a program that consists of two single-line statements. You can have as many statements as you need when writing programs.

document.getElementById("demo 1").innerHTML="Hello World!"
document.getElementById("demo 2").innerHTML="Hello Everyone!"

Grouping JavaScript Statements

JS statements can be grouped inside curly brackets {...}. These are called code blocks. Code blocks are used to make statements execute together. They are commonly used in functions.

function myfunc() {
document.getElementById("demo 1").innerHTML="Hello World!"
}

JavaScript Keywords

JS statements usually start with a keyword. Each keyword in JS has its own special meaning. For example, to declare a variable, we have to use the var keyword.

function myfunc() {
var text = "Hello World!";
document.getElementById("demo 1").innerHTML="Hello World!"
}

We will go through JavaScript keywords as you continue reading my articles. Thanks for reading this blog. Let me know what you think about it. PEACE!