Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
41 views

JavaScript Basics

This document provides a cheat sheet overview of JavaScript basics including data types, variables, constants, arrays, objects, functions, conditional statements, loops, and object methods. It covers topics like declaring variables and constants, accessing array elements, pushing/shifting arrays, conditional if/else statements, for/while loops, defining functions, and accessing object properties.

Uploaded by

Gopal Deshkari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

JavaScript Basics

This document provides a cheat sheet overview of JavaScript basics including data types, variables, constants, arrays, objects, functions, conditional statements, loops, and object methods. It covers topics like declaring variables and constants, accessing array elements, pushing/shifting arrays, conditional if/else statements, for/while loops, defining functions, and accessing object properties.

Uploaded by

Gopal Deshkari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Boolean

const isRaining = true;


Array & it's methods
const isAuth = false;
An array

JavaScript Basics
let ourArray = [“ ”, “ ”, “ ”, “ ”];
Objects
let user = { Access array elements
CHEAT SHEET fullname: “Bucky Barnes”,
age: 40,
ourArray[0]; //

gender: “male” Push


} ourArray.push(“ ”);

Console.log // output: [“ ”, “ ”, “ ”, “ ”,“ ”]

console.log(“JavaScript Cheat Sheet”);


Conditional Statements Shift
ourArray.shift();
if statement
// output: [“ ”, “ ”, “ ”, “ ”] --> “ ” removed

Variables & Constant if (isRaining){


wearRainCoat(); UnShift
} ourArray.unshift(“ ”);
Variables
// output: [“ ”, “ ”, “ ”, “ ”, “ ”, “ ”]
var variable_1; // global scope if else statement
let variable_2; // block scope
if (isRaining){ Combine two array - concat()
wearRainCoat(); const combine= [“ ”, “ ”, “ ”].concat([“ ”, “ ”, “ ”]);
Constants
} else { // Output: [“ ”, “ ”, “ ”,“ ”, “ ”, “ ”]
const constantVariable; // block scope
doNotWearRainCoat();
} forEach
Data Types else if statement
ourArray.forEach((elm) => console.log(elm));

Number if (isRaining){

let num = 3;
wearRainCoat(); Function
} else if (isRainingHeavy){
let floatData = 3.3;
sample function
doNotGoOut();
function sayHi() {
Strings } else {
console.log("Welcome to this Earth!");
const stringVaribale = “hello”; doNotWearRainCoat();
}
}
Arrays
call a function
let fruit = ["Banana", "Apple", "Orange"];
sayHi();
freeze
Scope Object.freeze(user);

JavaScript Basics Global Scope


The greet variable is accessible everywhere.
keys

CHEAT SHEET 02 let greet = `hello`; Object.keys(user);


function sayHello () { // output : [“fullname”, “place”];
console.log(greet);
} values
Arrow function sayHello(); // hello Object.values(user);
const sayHiAgain = () => // output : [“Thomas shelby”, “birmingham”];

console.log("Welcome to this Earth!");


Local Scope
The greet variable is accessible only inside sayhello function.
function sayHello () { Assignment Operators Arithmetic Operators
call an arrow function let greet = `hello`;
= Assignment operator + Addition
sayHiAgain(); console.log(greet);
+= Addition assignment - Subtraction
}
-= Subtraction Assignment * Multiplication
sayHello(); // hello

Loops *=

/=
Multiplication Assignment

Division Assignment %
/ Division

Remainder

for loop
Objects & it's methods %=

**=
Remainder Assignment

Exponentiation Assignment
**

++
Exponentiation (Power)

Increment (increments by 1)

-- Decrement (decrements by 1)
for (let i = 1; i <= 5; i++) {
The Object
console.log(`This is for loop.`);
let user = { Comparison Operators Bitwise Operators
}
fullname: “Thomas shelby”,
== Equal to & Bitwise AND
place: “birmingham”
while loop != Not equal to | Bitwise OR
} === Strict equal to ^ Bitwise XOR
while (i <= 3) {
!== Strict not equal to ~ Bitwise NOT
console.log(`This is while loop.`);
Access properties > Greater than << Left shift
i += 1; >= Greater than or equal to >> Sign-propagating right shift
console.log(user.fullname);
} < Less than >>> Zero-fill right shift
// Thomas Shelby
<= Less than or equal to
console.log(user.place);
do while loop
// birmingham
do {
console.log(`This is do while loop.`); Logical Operators
entries
i++; && Logical AND
} console.log(Object.entries(user)); || Logical OR

while (i < 5); // output ! Logical NOT


// [ ["fullname", "Thomas shelby"],
// ["place", "birmingham"]]

You might also like