JavaScript Tricks
Quick launch into Variables, Functions, Arrays, IJavaScript HTML, using Jupyter Notebooks
The first trick is the tunary operator.
const age = 13
age < 15 ? console.log("You underage homeboiii") : console.log("you big boi")
const age = 55
age > 50
? age > 70 ? console.log("You are getting really old")
: console.log("you are between 30 and 50")
: console.log("You are below 30");
The second trick is number to string.
const age = 20;
console.log(age);
console.log(typeof age);
The third trick is fill arrays.
const users = Array(5).fill("");
console.log(users);
The fourth trick is unique arrays.
const users = [
"Ed",
"Mr. John",
"Shruthi"
]
const unique = Array.from(new Set(users));
console.log(unique);
The 5th trick is Dynamic Objects.
const dynamic = "rest";
const users = {
name: "Shruthi",
email: "damodar.shruthi@gmail.com",
[dynamic]: "music"
};
console.log(users);
The sixth trick is slicing arrays.
const users = [1,2,3,4,5,6,7];
users.length = 3;
console.log(users);
The seventh trick is slicing arrays end.
const users = [1,2,3,4,5,6,7];
console.log(users.slice(-3));