Cannot understand this javascript statement [duplicate] - javascript

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

Related

What does the "this" keyword mean in JavaScript with a + before it [duplicate]

This question already has answers here:
What does this symbol mean in JavaScript?
(1 answer)
What does = +_ mean in JavaScript
(12 answers)
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
The code for this is not mine. I was just going over something and saw a + before the keyword this for the first time and was wondering what it does.
+this.closest('li').getAttribute('data-index');

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

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?

Result of syntax in JS [duplicate]

This question already has answers here:
How is this valid javascript, and what purpose does it serve?
(2 answers)
Closed 7 years ago.
I'm switching from C++ to JS.
//if ( condition )
{
instruction1;
instruction2;
}
In C/C++ commenting if before the block would simply execute the block unconditionally.
Could I use it the same way in JS? Or would it create an unnamed object which is never used?
A very quick way of testing:
{
alert("foo");
}
http://jsfiddle.net/4obksb0s/
Yes - it appears to run fine.

Categories