What is [, ... ] in function/method documentation? [duplicate] - javascript

This question already has answers here:
How to interpret function parameters in software and language documentation?
(4 answers)
Closed 6 years ago.
I have come across this type of syntax in Node.js. Can anyone please explain what [, is in Node.js/JavaScript?
Examples of syntax I have seen.
assert(value[, message])
const name1 = value1 [, name2 = value2 [, ... [, nameN = valueN]]];

You're looking at function definitions in documentation, and what you're seeing is a conventional way to show that one or more parameters are optional. It is not actually valid JavaScript syntax.
For example, assert(value[, message]) means that the value parameter is required, but message is optional. You could not actually put assert(value[, message]) in your code; it would trigger a syntax error.

Related

How to understand symbols in documentations [duplicate]

This question already has answers here:
How to interpret function parameters in software and language documentation?
(4 answers)
Closed 2 years ago.
I'm trying to get a good sense of reading documentation instead of asking so many questions here and there.
The first thing i'm confused of is the symbols.What do the symbols below mean?
example) app.use([path,] callback [, callback...])
reference source:https://expressjs.com/en/5x/api.html#app.use
Question1&2 can be solve by the similar posting.
Another example is like
bisector.left(array, x[, lo[, hi]])
what does x[, mean?
what does **lo[,**mean?
what does ,hi] mean?
reference source: https://devdocs.io/d3~5/d3-array#bisect
It would be very grateful if anyone could help me to under stand these cryptic symbols.
[xxx] means that this parameter is optional. You can use it or omit it.
[callback] is also an optional parameter. In this case it's a function that will be called under some circumstances.
Nested bisector.left(array, x[, lo[, hi]]) means that you need to have some options before you can specify others. For example, you cannot specify lo in this case without specifying hi first.

What is the reason of using $$ while defining object property in JavaScript [duplicate]

This question already has answers here:
What is the $$ (double dollar sign) used for in angular?
(2 answers)
Closed 5 years ago.
I find this code in a AngularJS base front-end application:
var xyz= {
FileUrl: "some url value",
CreatedDate: new Date(),
$$file: "some value in base64 format for file"
};
I search through net but I, do not find any good answer why $$ use for defining object property of JavaScript. I mean what is benefit of using $$ in object property.
$$ means that it's a private variable.
Edit:
This is just a naming convention used by Angular to signal you that you shouldn't use this property directly, as they could remove it or change the usage in a future release.
Since it's just a naming convention, nothing in Javascript prevents you to use it though, however you shouldn't really do it for the reason mentioned above.

Javascript square brackets used in function call [duplicate]

This question already has answers here:
What is array literal notation in javascript and when should you use it?
(4 answers)
Closed 6 years ago.
im a newbie javascripter, coming from c++/c#.
im learning a tutorial which has the following lines:
​function getUserInput(firstName, lastName, callback, callbackObj) {
​
callback.apply (callbackObj, [firstName, lastName]);
}
this was an example of using a callback function inside another function.
and i was wondering about this line :
callback.apply (callbackObj, [firstName, lastName]);
what is the meaning of using a [ ] inside a function?
This is a literal for an array. In this case it consists of 2 elements, the first being firstName the second lastName.
Since you are using apply, the assumption is that the callback method signature has 2 string parameters: firstName and lastName. The callbackObj is the context being passed to the method (in case it will call this)
More info here

Javascript documentation notation [duplicate]

This question already has answers here:
What do the brackets around the arguments mean when reading documentation for a method? [duplicate]
(3 answers)
Closed 6 years ago.
I've seen this a lot and most of the time I can figure out what it means, but there have been times when I was a bit confused. Looking at documentation mostly on jquery i see something like this:
.toggleClass( function [, state ] )
what does the bracket notation with the comma and state mean exactly?
Any info would be awesome.
Thanks!
Everything between the brackets [] is optional.
In your case it means that state can be omitted, and the function will still work.
Optional parameters.
Those marked inside such as state in your case can be omitted and the function will not throw an error.
For another example:
jQuery.ajax( url [, settings ] )
Means both
jQuery.ajax( "www.google.com" )
and
jQuery.ajax( "www.google.com" , {dataType: 'mycustomtype'} )
are valid.

Does JavaScript have a defined order of evaluation for function parameters? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is the order of evaluation for function arguments in Javascript?
If I run the following code in Chrome, the parameters to the anonymous function are evaluated left-to-right:
(function () {})(console.log(1), console.log(2));
Is this defined in the specification or is it implementation-defined?
Yes, it is part of the ECMAScript 5 documentation:
Let names be a List containing, in left to right textual order, the Strings corresponding to the identifiers of FormalParameterList. If no parameters are specified, let names be the empty list.
Source: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf (Pg 99)

Categories

Resources