0% found this document useful (0 votes)
73 views

JS Short Hand

The document summarizes 10 JavaScript tricks that every developer must know, including ternary operators, short-circuit evaluation, object property shorthand, destructuring assignment, spread operator, Array map, filter and reduce methods, arrow functions, template literals. It provides examples for each trick.

Uploaded by

Sai Ram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

JS Short Hand

The document summarizes 10 JavaScript tricks that every developer must know, including ternary operators, short-circuit evaluation, object property shorthand, destructuring assignment, spread operator, Array map, filter and reduce methods, arrow functions, template literals. It provides examples for each trick.

Uploaded by

Sai Ram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Top 10 JavaScript

Short Hand Tricks

Part - 1

Every Developer
Must Know

Paras Mayur
Ternary Operator

We can use the ternary operator to write a


simple if-else statement in one line.

Example: let x = (a > b) ? "a is greater" : "b is


greater";

Short-circuit evaluation

We can use the logical AND (&&) and OR (||)


operators to perform short-circuit evaluations.

Example: let x = (a > b) && "a is greater" || "b is


greater";
Scan & Join

Paras Mayur FrontEnd Community


Object Property Shorthand

When creating an object, we can use


shorthand notation for properties that
have the same name as variables.

Example: let x = 5, y = 10; let obj = {x, y};


Paras Mayur

Destructuring Assignment

We can use destructuring assignment to


extract values from arrays or objects
and assign them to variables.

Example: let arr = [1, 2, 3]; let [x, y, z] =


arr;
Spread Operator

We can use the spread operator (...) to spread


the elements of an array or object into a new
array or object.

Example: let arr1 = [1, 2, 3]; let arr2 = [...arr1, 4,


5];
Paras Mayur

Array.map() Method

We can use the map() method to create a


new array with the results of calling a
provided function on every element in the
calling array.

Example: let arr = [1, 2, 3]; let newArr =


arr.map(x => x * 2);
Paras Mayur
Array.filter() Method

We can use the filter() method to create a


new array with all elements that pass the test
implemented by the provided function.

Example: let arr = [1, 2, 3, 4, 5]; let newArr =


arr.filter(x => x % 2 === 0);

Array.reduce() Method

We can use the reduce() method to apply a


function to each element in an array and
reduce it to a single value.

Example: let arr = [1, 2, 3, 4, 5]; let sum =


arr.reduce((acc, val) => acc + val, 0);

Paras Mayur
Arrow Functions

We can use arrow functions to create shorter,


more concise function expressions.

Example: let sum = (a, b) => a + b;

Paras Mayur

Template Literals

We can use template literals (backticks) to


create strings that contain expressions.

Example: let x = 5, y = 10; console.log(The


sum of ${x} and ${y} is ${x + y}.);

Paras Mayur
@ParasMayur

Was it helpful?

Like Comment Share Save

Paras Mayur
Scan & Join

FrontEnd Community

You might also like