Question mark after JS array variable, but before .length [duplicate] - javascript

This question already has answers here:
Question mark after parameter as in obj.val?.prop [duplicate]
(3 answers)
What does this symbol mean in JavaScript?
(1 answer)
Optional Chaining in JavaScript [duplicate]
(8 answers)
Closed 7 months ago.
I'm trying to understand this piece of code:
!isLoading && !QRCodes?.length ? (.....
What is the role of ? in !QRCodes?.length? Wouldn't be the statement false anyway, when there's no QRCodes?

!isLoading means if not loading and the QRCodes length is 0 display the thing after the (...
the question mark in QRCodes?.length means that get length if exists

Related

Cannot understand this javascript statement [duplicate]

This question already has answers here:
Javascript || operator
(5 answers)
Javascript Shorthand - What Does the '||' Operator Mean When Used in an Assignment? [duplicate]
(6 answers)
JavaScript OR (||) variable assignment explanation
(12 answers)
Closed 3 months ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
I've been given a function by a client to create a custom script for tracking purposes which is fine, but being new to JS I'm having trouble understanding this line of code:
d[p]=d[p]||function(){(d[p].q=d[p].q||[]).push(arguments);};
function example is:
(function (d,e,k,u,p) {
d[p]=d[p]||function(){(d[p].q=d[p].q||[]).push(arguments);};
var a=e.createElement(k),b=e.getElementsByTagName(k)[0]; a.async=1;a.src=u;b.parentNode.insertBefore(a, b);
}(window,document,'script','https://www.example.com/bundle.js','stringname'));
If anyone could explain it that would be great
Just want to understand the statement better, it works fine and I can copy and paste with the correct url and string name but better if I understand the statement

Is null a primitive type or object or bug in Javascript? [duplicate]

This question already has answers here:
Why is null an object and what's the difference between null and undefined?
(25 answers)
JavaScript: What is the data type of null? [duplicate]
(1 answer)
Why is typeof null "object"?
(11 answers)
Closed 2 years ago.
I have been looking for the answer and gone through articles where some says its bug in javascript and consoling it in browser gives object.If so then why (null === null) is true.can anyone give clear explanation regarding this?

What does this syntax mean " function(a,d){...}(Jquery,...); " [duplicate]

This question already has answers here:
What is the (function() { } )() construct in JavaScript?
(28 answers)
What does this symbol mean in JavaScript?
(1 answer)
Closed 2 years ago.
I know, similar questions have been asked but none answered my question of What does the second () mean?
And also no the syntax is not (function...) rather its just function(a,d){...}(Jquery,...);
Is it that we are making objects of Jquery, I am also using Hammer.js so basically the second paranthesis has (Jquery, Hammer)

What does ! mean in the context of react refs? [duplicate]

This question already has answers here:
In Typescript, what is the ! (exclamation mark / bang) operator when dereferencing a member?
(5 answers)
Closed 3 years ago.
I was looking through the react-data-grid source code and noticed this line: https://github.com/adazzle/react-data-grid/blob/34a2e51931bba2ac8a2f738cd059945d66516b48/packages/react-data-grid/src/HeaderCell.tsx#L107
return x - this.cell.current!.getBoundingClientRect().left;
I can't seem to figure out what the ! is doing.
That means that you are sure that variable value this.cell.current is not undefined or null

Refactoring JavaScript / TypeScript: Avoiding repeating properties [duplicate]

This question already has answers here:
Does TypeScript have a Null-conditional operator
(8 answers)
JavaScript, elegant way to check nested object properties for null/undefined [duplicate]
(4 answers)
Closed 3 years ago.
EDIT: Existing answers are 2 and 5 years old (from 2017 and 2014).
How can I shorten the following statement
ratingsExisting(): boolean {
return (
this.fromAPIData.book &&
this.fromAPIData.book.misc &&
this.fromAPIData.book.misc.ratings &&
this.fromAPIData.book.misc.ratings.length > 0
);
}
so that I don't receive errors if any of the properties is null?

Categories