Premium Only Content

`_.defaults` function on object using JavaScript Library underscore.js ( #shorts )
Hi Friends,
`_.defaults` function on object using JavaScript Library underscore.js
`_.defaults` is a utility function in Underscore.js library that ensure if an object has certain properties with default values, in case those properties are missing or undefined.
In below example, we have an object options that represents various options. We use _.defaults to set default values for the city and profession properties in case they are missing or undefined in the options object. After applying _.defaults, the options object is modified to include the default values for those properties.
Note: You can pass multiple default objects as arguments to _.defaults.
// syntax
_.defaults(object, *defaults)
// example
var options = {
name: "Alice",
age: 26
};
_.defaults(options, {
city: "New York",
profession: "Engineer"
});
console.log(options);
// { name: "Alice", age: 26, city: "New York", profession: "Engineer" }
#javascript #under #score #underscore #underscorejs #default #underscoredefaults #defaultsfunction #unique #object #array #string #nodejs #javascriptinterview #method #js #jquery #function #shorts #viral #popular #latest #new #coders #development #code #dev #interview #php #trend #trending #answer #laravel #youtube #instagram #socialmedia #education #edit #how #india #knowledge #quiz #reels #short #subscribe #share #update #video #web #webdeveloper #website #webdesign #ytshorts #youtuber #princecheema_official @princecheema_official
-
2:44:58
Barry Cunningham
7 hours agoPRESIDENT TRUMP IS LEADING AMERICA TO PROSPERITY! WHAT A DAY!
68.4K48 -
2:32:33
The Quartering
6 hours agoTrump Epstein "Bombshell" From Wall St. Journal Then Expedition 33!
90.5K26 -
LIVE
SpartakusLIVE
8 hours ago$1,000 Spartakus Gauntlet on VERDANSK for the FIRST TIME || TrulyEvil, Enzo Alder, Firefighter MDO
236 watching -
1:21:42
AimControllers
6 hours ago $1.45 earned🔴LIVE - TRIVIA NIGHT WITH PRIZES COME PLAY!
31K1 -
1:45:13
RiftTV
8 hours agoLast Catholic Church in Gaza DESTROYED, Targeted by IDF? | The Rift | with Sarah Stock & Anna Perez
53.4K34 -
4:55:21
PudgeTV
7 hours ago🟢PEAK - Gaming on Rumble | Community Gaming Night
11.2K -
1:33:33
Precision Rifle Network
1 day agoS4E23 Guns & Grub - Gear We H8, Politics, & New Optics
15.6K -
4:51:16
FatHeadedNoob
6 hours agoStaying In My Lane | Red Dead Redemption 2
5.32K2 -
18:55
Tundra Tactical
11 hours ago $0.91 earnedGun Show Weirdos
11.3K1 -
3:20:00
OVERKLOC
6 hours ago $0.02 earned🔴LIVE - AMONG THE SLEEP - CHAT ASKS... CHAT GETS
2.44K