I want to ask mean of plus operator in this script +i+ in the follow:
i=0;
// next line in scripts write this code :
$('.container[data-id='+i+']').hide(); // +i+ what the meaning of it
Need He开发者_如何学Clp thanks a TON
+
is used to concatenate strings
In this case, it is used to concatenate the value of i
between .container[data-id= and ]
Assuming that i is storing some value eg 0, then this will be evaluated to
$('.container[data-id=0]').hide();
This will concatenate the value in the variable i
with the remaining string.
See Concatenating strings
+ is used for string concantination
var test= "hello" + "world";// gives helloworld
it is used for adding values also
var c= a+ b// if a=10 and b=20 it gives 30
The +
operator in JavaScript is used for both Arithmetic and String operations.
If both operands are of Number
type, the result is the sum. If either of the operands is not a number, then both will be converted to String
and concatenated. It should be used with care.
精彩评论