Skip to content

Commit 6b872d0

Browse files
author
krishna9802
committed
first code snippet addded
1 parent 0358cbb commit 6b872d0

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,27 @@ One liner clean code snippets in javascript/react with ES6 syntax
1616

1717
1. ### Add a key-value pair in object conditionally
1818

19-
Spread operator is used to spread one object and conditional operator && to achieve the task conditionally
19+
20+
21+
**Plain conditional operation**
22+
23+
```javascript
24+
const is_employee=true;
25+
26+
const student={
27+
name:'Krishna Kant',
28+
roll:'AD203',
29+
stream:'MERN stack web development',
30+
...(is_employee && {company:'Inventives.ai})
31+
}
32+
33+
if(is_employee){
34+
student.company='Inventives.ai';
35+
}
36+
```
37+
38+
39+
We will use Spread operator to spread new object with one property inside the previously defined object and the conditional operator `&&` to achieve the task conditionally
2040
2141
1. **While defining the object:**
2242
@@ -33,7 +53,7 @@ One liner clean code snippets in javascript/react with ES6 syntax
3353
}
3454
```
3555

36-
2. **After object has been defined**
56+
2. **After object has been defined**
3757

3858
We are injecting the new property after the object has been defined with its default key value pairs.
3959

0 commit comments

Comments
 (0)