Ramda.js R.propOr() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.propOr() answers a one-key question with a fallback: what value sits at this property, or else this default? You pass the default, the key, then the object. You get the property, or the default if it is missing or empty. Native JavaScript’s cousin is obj?.name ?? 'anon'. That is data-first. propOr is data-last, so R.propOr('anon', 'name') is already a function of one object — ready for R.map or R.pipe.

The official sample is the whole idea. Alice is {name: 'ALICE', age: 101}. She has no favoriteLibrary. R.prop('favoriteLibrary')(alice) is undefined. R.propOr('Ramda', 'favoriteLibrary')(alice) is 'Ramda'. Need nested keys with a default? That is R.pathOr. Need the leftover without a default? Stay on R.prop. Need several keys? That is R.props.

Syntax

Call R.propOr. Start with this line.

Ramda
R.propOr(val, p, obj)
CallWhat it does
R.propOr(val, p, obj)Primary signature.
R.propOr(...)Call the object helper.

Prefer import { propOr } from "ramda" when you want a named import.

Library declarations
Ramda
R.propOr(val, p, obj)

Parameters

ParameterDescription
valRequired. Any. The default. Used when the property is missing or the value is undefined, null, or NaN.
pRequired. String (or number). The property name. Integers work as array indexes through R.prop / nth.
objRequired. Object or Array. The source. null and undefined yield the default. The source is never mutated.

Return Value

Return ValueDescription
AnyThe property value, or val when the lookup fails or defaultTo treats the leftover as empty. Falsy values such as 0 and false are kept.

Ramda Examples

📚 Getting Started

The official Alice sample, then the defaultTo rules for zeros, empties, null, and NaN.

Example 1 — Official Alice Favorite Library

A missing property is undefined with prop. The same lookup with propOr returns the default.

Ramda
const alice = { name: 'ALICE', age: 101 };
const favorite = R.prop('favoriteLibrary');
const favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary');

favorite(alice);
//=> undefined

favoriteWithDefault(alice);
//=> 'Ramda'
Try It Yourself

How It Works

Alice has name and age, but no favoriteLibrary. R.prop leaves that hole as undefined. R.propOr runs the same lookup, then defaultTo swaps in 'Ramda'. That is the docs sample from ramdajs.com.

Example 2 — Keep 0 and false, Fall Back on null

defaultTo treats null, undefined, and NaN as empty. Real zeros, false, and empty strings stay.

Ramda
R.propOr(99, 'n', {n: 0});
//=> 0

R.propOr(true, 'ok', {ok: false});
//=> false

R.propOr('anon', 'name', {name: ''});
//=> ''

R.propOr('N/A', 'a', {a: null});
//=> 'N/A'

R.propOr('N/A', 'a', {a: undefined});
//=> 'N/A'

R.propOr('N/A', 'n', {n: NaN});
//=> 'N/A'
Try It Yourself

How It Works

The test is v == null || v !== v. 0, false, and '' fail that test, so they are kept. null, undefined, and NaN pass it, so you get the default. Do not mix this with ||, which would also replace 0.

📈 Practical Patterns

Compare cousins, then a curried helper, then a null object and an array index.

Example 3 — vs prop, pathOr, and defaultTo

prop leaves undefined. propOr fills it. pathOr is nested. defaultTo is the same swap after you already have the leftover.

Ramda
const miss = {age: 101};
R.prop('name', miss);
//=> undefined
R.propOr('anon', 'name', miss);
//=> 'anon'

R.pathOr('N/A', ['user', 'name'], {user: {name: 'Ada'}});
//=> 'Ada'

R.defaultTo('anon', R.prop('name', miss));
//=> 'anon'
Try It Yourself

How It Works

prop and propOr share the lookup. Only the leftover differs. R.pathOr is the nested cousin. Internally, propOr is exactly defaultTo(val, prop(p, obj)), so the last line matches the second.

Example 4 — Curry and Map

Fill the default and the key to map over rows. Missing names become 'anon'.

Ramda
const userName = R.propOr('anon', 'name');

R.map(userName, [
  { name: 'Ada' },
  { name: null },
  {}
]);
//=> ['Ada', 'anon', 'anon']
Try It Yourself

How It Works

Because propOr is arity 3, filling the default and the key leaves a function of one object. R.prop('name') would put undefined (and null) in the last two slots. propOr keeps the list full of strings.

Example 5 — Null Object, Missing Key, Array Index

A null object does not throw. A missing key uses the default. An integer key reads an array slot through prop / nth.

Ramda
R.propOr('N/A', 'name', null);
//=> 'N/A'

R.propOr('N/A', 'name', {age: 101});
//=> 'N/A'

R.propOr(-1, 0, [100, 200]);
//=> 100

R.propOr(-1, 9, [100, 200]);
//=> -1
Try It Yourself

How It Works

Native null.name throws. R.prop on null is undefined, so propOr returns the default. Index 0 uses nth just like R.prop. Index 9 is off the list, so you get -1. Nested keys still belong on R.pathOr.

Browser Support

R.propOr() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.6.0+ · Any JS runtime

Ramda.js R.propOr()

Load Ramda 0.6.0 or later via CDN or npm, then call R.propOr with a default, a property name, and an object. No extra browser API is required.

100% With Ramda 0.6.0+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
R.propOr() Universal

Bottom line: Safe in any project that includes Ramda 0.6.0 or later. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected].

Frequently Asked Questions

R.propOr(default, key, obj) returns that property if it is present and not null, undefined, or NaN. Otherwise it returns default. Added in v0.6.0. The original object is not mutated.
On alice = {name: 'ALICE', age: 101}, R.prop('favoriteLibrary')(alice) is undefined. R.propOr('Ramda', 'favoriteLibrary')(alice) is 'Ramda'.
prop returns undefined on a miss. propOr substitutes a default. pathOr is the nested-path cousin. Internally propOr is defaultTo(val, prop(p, obj)).
Yes. defaultTo treats undefined, null, and NaN as empty. 0, false, and '' are kept.
No. R.prop on null is undefined, so propOr returns the default. Native null.x throws.
No. R.propOr is a stable Ramda object helper from v0.6.0. It is not deprecated, experimental, or non-standard.

Continue to R.props()

Learn how to read several properties at once using Ramda R.props().

R.props() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful