`_.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
-
30:01
World Nomac
16 hours agoI Visited the Long Neck Tribe of Thailand 🇹🇭
3.03K21 -
9:28
ThinkStory
1 day agoOUTER RANGE Season 2 Ending Explained!
5.19K4 -
16:43
TudorDixon
23 hours agoHow was Harrison Butker Wrong? | The Tudor Dixon Podcast
5.67K29 -
2:39:22
Drunk3PO
18 hours agoStar Wars, Achromatic Chronicles Green, & More | Drunk3po Live
6.44K4 -
7:11
Film Threat
1 day agoTHE STRANGERS: CHAPTER 1 | Film Threat Reviews
6.31K4 -
25:22
MYLUNCHBREAK CHANNEL PAGE
17 hours agoTartaria, Russia & The Old World?
6.91K20 -
15:08
justintech
21 hours agoCorsair Vengeance i8200 Review - 14900K + 4090
9.96K2 -
11:31
ryanhoguepassiveincome
15 hours agoTOP 5 NICHES 🔥 Print on Demand Niche Research # 207 — (5/12/2024)
4.48K1 -
51:31
Science & Futurism with Isaac Arthur
23 hours agoAutomated Justice
11.7K4 -
28:23
TampaAerialMedia
22 hours agoMiami Travel Guide - Downtown, Key Biscayne, Coral Gables
4.43K2