DEV Community

Nazmus Sakib
Nazmus Sakib

Posted on • Updated on

JavaScript Fundamentals: Explained in a Nutshell

JS Variables

JS variables usually declared by var
var x = 5;
Using ES6 (JS version 2015) variables are declared by let or const
let x = 5; //Can be changed
const y = 10; //Can't be changed

JS Operator

+ Addition
- Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
% Modulus (Remainder)
++ Increment
-- Decrement

JS Data Types

JS has basically 4 types of data and more...
var length = 16; // Number
var lastName = "Johnson"; // String
var x = {firstName:"John", lastName:"Doe"}; // Object
var cars = ["Saab", "Volvo", "BMW"]; // Array

JS Condition

To different action based on different condition we need to use conditional statements.
if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}

JS Loop

To execute same code again & again, loops are used.
for (i = 1; i < 6; i++) {
console.log("Number: "+i);
}

Top comments (0)