开发者

what the meaning of plus operator in this JQUERY scripts

开发者 https://www.devze.com 2023-01-30 01:27 出处:网络
I want to ask mean of plus operator in this script +i+ in the follow: i=0; // next line in scripts write this code :

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 ibetween .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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号