You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-2Lines changed: 22 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,27 @@ One liner clean code snippets in javascript/react with ES6 syntax
16
16
17
17
1.### Add a key-value pair in object conditionally
18
18
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
+
constis_employee=true;
25
+
26
+
conststudent={
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
20
40
21
41
1. **While defining the object:**
22
42
@@ -33,7 +53,7 @@ One liner clean code snippets in javascript/react with ES6 syntax
33
53
}
34
54
```
35
55
36
-
2. **After object has been defined**
56
+
2.**After object has been defined**
37
57
38
58
We are injecting the newproperty after the object has been defined with its default key value pairs.
0 commit comments