Linked Questions
31 questions linked to/from Is there a null-coalescing (Elvis) operator or safe navigation operator in javascript?
13
votes
2
answers
6k
views
Does ES6 support the Elvis operator? [duplicate]
Does Javascript / ES6 support the Elvis operator?
Example:
var x = (y==true) ?: 10;
Example 2:
var debug = true;
debug ?: console.log("Value of x:" + x);
2
votes
2
answers
1k
views
What does ?? ternary operator mean using react and javascript? [duplicate]
i have code like below,
const output = (data?.item?.someItem?.count ?? 0) === 0;
what is the value of output in this case what does ?? in above line mean. could someone help me understand this line ...
-2
votes
2
answers
447
views
How to use itenary operator? [duplicate]
I have conditional $stateParams on $state and i am trying to assign current $stateParams value to paramId. How can i achieve that task using ternary operator?
commonCtrl.js
var paramId = $...
2
votes
1
answer
711
views
What does ?. and ?? mean in javascript [duplicate]
Here in below code what does ?. and ?? mean
history.replace(loacation.state?.redirectPath ?? '/home')
1
vote
1
answer
87
views
How to simplify the expression "data && data.pwd && data.pwd.length"? [duplicate]
I'm sorry if this question has been asked several times and in much clearer terms, but I just don't know the technical term for what I'm looking for. I'm trying to write a conditional statement in the ...
1
vote
0
answers
123
views
what does ?? mean in JS [duplicate]
I have recently seen ?? in JS, or maybe it's a Typescript thing. It seems to behave the same as ||
code looks something like this
import GeneralImage from './images'
const Team = ({ teamImg }) =>...
-2
votes
1
answer
95
views
Is there a shortcut for b && b.c && b.c.d ? b.c.d : "default"; [duplicate]
If I want to set a constant with a value from a nested object property that can be undefined or set it to a default value, I can do this:
const a = b && b.c && b.c.d ? b.c.d : "...
2
votes
1
answer
86
views
Is there a way to work with an Object in Object typescript? [duplicate]
I have worked with React and Typescript and fetch a data from API. After fetching data, it will be saved as coin object. And I absorb at the pending state, it may not have a data. So, coin can be ...
0
votes
1
answer
63
views
Check nested js object properties in js [duplicate]
I'd like to check the existence of a nested js object property, any way to simplify this code in one line?
if(json_root.hasOwnProperty(p1)){
if(json_root.p1.hasOwnProperty(p2)){
if(...
0
votes
1
answer
47
views
JS shorterhand conditional? [duplicate]
I am using the following shorthand conditional in JS/jQuery:
var delay = $(this).data("delay") ? $(this).data("delay") : options.delay;
If the element has a data-delay attribute ...
0
votes
1
answer
68
views
Is there something similar to the 'or operator' that treats 0 as a number instead of false? [duplicate]
I'm trying to make a simple Vector class in Javascript, but since it doesn't support overloading, I experimented with the 'or operator' and came up with the following add function. It works with most ...
0
votes
1
answer
45
views
Javascript Variable checking shorthand [duplicate]
I'm wondering if there's a shorthand way to write something like this in JavaScript
if (thingExists) {
thingExists.manipulate
}
I think I remember seeing something along the lines of
...
0
votes
0
answers
35
views
What are the differences among ?. , ??, ? and && in javascript? [duplicate]
Here is an example to become more specific. All of the answers is same. If i face some challenge which way should i follow ? Actually how they work with their own logic. Want to be clear.
var obj = {
...
0
votes
0
answers
23
views
fallback for dynamic object using bracket [duplicate]
const result = something[dynamicValue]
Given the above code, I can get error of Cannot read property 'x' of null because something is undefined, how do I fallback check to void error? should I do ...
0
votes
0
answers
23
views
way to check "value" of undefines [duplicate]
Is there a clean way to check for this ?
I am using typescript, and I have a big object with many optional value
I want to access,
value1.subValue1.subsubValue1;
but if subValue1 that is optional ...