Javascript Basic Concepts 💫

What Is JavaScript Used For?
Of course, JavaScript wouldn’t be a cornerstone of the programming world if it was just about pressing buttons. The practical applications of JavaScript are almost endless, but we’ve highlighted some of the most common uses down below.
⚫️ JavaScript Output
JavaScript Display Possibilities
JavaScript can "display" data in different ways:
- Writing into an HTML element, using innerHTML.
- Writing into the HTML output using document.write().
- Writing into an alert box, using window.alert().
- Writing into the browser console, using console.log().
You should know!
Using document.write() after an HTML document is loaded, will delete all existing HTML
JavaScript Statements
let x, y, z; // Statement 1 x = 5; // Statement 2 y = 6; // Statement 3 z = x + y; // Statement 4
A good practice is to put spaces around operators ( = + - * / ):
document.getElementById("demo").innerHTML = "Hello Imran";
JavaScript Programs
- A computer program is a list of "instructions" to be "executed" by a computer.
- In a programming language, these programming instructions are called statements.
- A JavaScript program is a list of programming statements.
JavaScript Syntax
// How to create variables: var x; let y; // How to use variables: x = 5; y = 6; let z = x + y;
JavaScript Values
The JavaScript syntax defines two types of values:
- Fixed values
- Variable values
Fixed values are called Literals.
Variable values are called Variables.
JavaScript Literals
The two most important syntax rules for fixed values are:
- Numbers are written with or without decimals:
10.50 1001
- Strings are text, written within double or single quotes:
"Imran" 'imran'
JavaScript Variables
In a programming language, variables are used to store data values. JavaScript uses the keywords var, let and const to declare variables.
let x; x = 6;
- In these examples, using var or let will produce the same result.
- You will learn more about var,let and const later in comming tutorial.
JavaScript Operators
JavaScript uses arithmetic operators ( + - * / ) to compute values:
(5 + 6) * 10
JavaScript uses an assignment operator ( = ) to assign values to variables:
let x, y; x = 5; y = 6;
JavaScript Comments
Not all JavaScript statements are "executed".
Code after double slashes // or between /* and */ is treated as a comment.
let x = 5; // I will be executed // x = 6; I will NOT be executed
JavaScript Data Types
JavaScript has 8 Datatypes
- String
- Number
- Bigint
- Boolean
- Undefined
- Null
- Symbol
- Object
The Object Datatype
The object data type can contain 👇🏾
- An object
- An array
- A date
// Numbers: let length = 16; let weight = 7.5; // Strings: let color = "Yellow"; let lastName = "Johnson"; // Booleans let x = true; let y = false; // Object: const person = {firstName:"John", lastName:"Doe"}; // Array object: const cars = ["Saab", "Volvo", "BMW"]; // Date object: const date = new Date("2022-03-25");