1. Declaring Variables
Longhand
let firstName;
let lastName;
let surName = "beast";
Shorthand
let firstName, lastName, surName = "beast";
2. Ternary Operators
Longhand
let answer, value = 15;
if(value%2 = 0)
{
answer = "Number is even";
}else{
answer = "Number is not even";
}
Shorthand
let answer = value&2 = 0 ? "Number is even" : "Number is not even"
3. Ternary Short For-Loop
Longhand
const languages = ["html","css","js"];
for(let i = 0;i < language.length;i++){
const languages = languages[i];
console.log(languages);
}
Shorthand
for(let languages of languages)console.log(languages);
4. Template Literals
Longhand
const fullName = "codingBeast";
const timeOfDay = "afternoon";
const greeting = "Hello" + fullName + ", I wish you a good" + timeOfDay + "!";
Shorthand
const greeting = `Hello ${fullName}, I wish you a good ${timeOfDay}`;
5. Assignment Operator
Longhand
a = a+b;
a = a-b;
Shorthand
a += b;
a -= b;
6. Object Array Notation
Longhand
let arr = new Array();
arr[0] = "html"
arr[1] = "css";
arr[2] = "js";
Shorthand
let arr = ["html","css","js"];
7. Arrow Function
Longhand
function addition(a,b){
console.log("addition",a + b);
}
Shorthand
addition = (a,b) => console.log("addition", a + b);
8. Identical key and Values
Longhand
const userDetails = {
name: name, // key:value
email: email,
age: age,
location: location,
};
Shorthand
Top comments (0)