Found this golden relic while researching an open API.

Found this golden relic while researching an open API.

It bothers me that I don't know if the ternary operator happens first or the comparison. What bothers me even more is it doesn't matter either way.

opt.VerifySsl !== false Would have sufficed then.

Image Transcription: Code

[Function name is redacted. The entire 14th line starting with this.verifySsl is highlighted in a square.]

/** * Set default options * * @param {Object} opt */ ██████████████.prototype._setDefaultsOptions = function(opt) { this.url = opt.url; this.wpAPI = opt.wpAPI || false; this.wpAPIPrefix = opt.wpAPIPrefix || 'wp-json'; this.version = opt.version || 'v3'; this.isSsl = /^https/i.test(this.url); this.consumerKey = opt.consumerKey; this.consumerSecret = opt.consumerSecret; this.verifySsl = false === opt.verifySsl ? false : true; this.encoding = opt.encoding || 'utf8'; this.queryStringAuth = opt.queryStringAuth || false; this.port = opt.port || ''; this.timeout = opt.timeout; };

I'm a human volunteer content transcriber for Reddit! If  you'd like more information on what we do and why...

It bothers me that I don't know if the ternary operator happens first or the comparison. What bothers me even more is it doesn't matter either way.

I'm ashamed to admit that I knew off the top of my head (it's comparison first), based on how much stodgy function-entry code I write that relies heavily on ternaries. (Though to be fair, I always wrap in parenthesis).

Possible dumb question: what's so weird about this? The expression makes sure the types match and that opt.verifySsl isn't just some falsy null-like value, which makes sense to me.

human = (GOOD*) malloc(sizeof(GOOD));

That would convert null to false. The expression in the image converts null to true.

What bothers me even more is it doesn't matter either way.

You just blew my mind.

It does matter. This line ensure the value is cast to a boolean.

You could do this.verifySsl = !opt.verifySsl, but this does not have the same behavior.

In case you want to convert possible undefined/null input into boolean: !!opt.verifySsl

on the other hand, they don't check if opt.timeout is a positive number

Good bot