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

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

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

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

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

JavaScript object properties copy syntax [duplicate]

This question already has answers here:
What does this symbol mean in JavaScript?
(1 answer)
What does curly brackets in the `var { ... } = ...` statements do?
(4 answers)
What do {curly braces} around javascript variable name mean [duplicate]
(1 answer)
Closed 4 years ago.
I was reading some JavaScript code and saw a line of code similar to this.
const {name, password, email} = user;
I tried searching around but could not figure out what this syntax is called so I am not able find the documentation. Is this a new JavaScript syntax? What is it called? What does it do exactly?

What does exclamation point after variable mean in JavaScript? [duplicate]

This question already has answers here:
In Typescript, what is the ! (exclamation mark / bang) operator when dereferencing a member?
(5 answers)
Closed 5 years ago.
I've seen in some React/TypeScript implementations such as :
ref={ ref => this.container = ref! }
What does the exclamation point means in ref!?
Is that something specific in TypeScript, or a new standard JavaScript notation?
In TypeScript, a postfix ! removes null and undefined from the type of an expression.
This is useful when you know, for reasons outside TypeScript's inference ability, that a variable that "could" be null or undefined actually isn't.

Reversing a variable in javascript [duplicate]

This question already has answers here:
How do you reverse a string in-place in JavaScript?
(57 answers)
Closed 8 years ago.
I don't really have a good way to explain in words what i wont to do.So im just going to have an example.
this is what the variable would be before.
var foo ="foo";
this is what i wont it be after.
var foo ="oof";
I hope that you under stand what i'm asking!
Thinks !
Try this:
var foo="start".split("").reverse().join("");

Categories