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:45
SLS - Street League Skateboarding
4 days agoManny Santiago's 'THIS IS 40' Part
18.3K2 -
6:40
Homesteading Family
5 days agoNever Make Pie Crust From Scratch Again (Do THIS Instead)
14.2K2 -
44:20
Melissa K Norris
3 days ago $0.30 earnedThe Most Overlooked Way to Preserve Food for Months (No Freezer Needed) w/ Sam Knapp
10K1 -
23:00
Tony Jeffries
6 days agoThe Best & Worst Boxing Training Methods (Ranked by Olympic Boxer)
7.06K -
44:44
Scammer Payback
17 days agoCrazy Confrontation with Hacked Scammer Group
34K20 -
1:15:13
Steven Crowder
3 hours agoIt Isn't Both Sides: They Crossed The Rubicon When They Killed Charlie
348K315 -
1:26:36
The Rubin Report
2 hours ago'Real Time' Crowd Goes Quiet as Bill Maher & Ben Shapiro Have a Tense Exchange About Charlie Kirk
33.6K49 -
1:49:25
Benny Johnson
3 hours agoTrump Launches 'Major Investigation' of Leftist Plot in Charlie Kirk Murder, FBI New Evidence…
83.8K83 -
1:01:26
VINCE
4 hours agoA Turning Point In The Culture | Episode 125 - 09/15/25
223K316 -
1:40:09
Dear America
4 hours agoBREAKING NEWS UPDATE! Dark Truth EXPOSED: Charlie Kirk's Assassin & the Trans Agenda-This Is WAR!
153K135