+ 2
Can any one tell what's the use of { and } in js.
6 Réponses
+ 1
{ } represent body for any statement or expression.
for any given statement or expression all the codes inside { } brackets will be executed once or multiple time.
you can check this function statement...
function add() {
return 1 + 1;
}
now when you invoke/run/execute the function add(), code inside function body starting from { to } will be executed.
for simplicity you can think {} as a wrapper or a container of some codes
+ 2
example:
if(x> 1){
//some code
}
this is scope, defining what code segments belongs to the if condition.It defines what are Global variables and local... variables
for more info:
https://www.w3schools.com/js/js_scope.asp
+ 1
to contain some code
+ 1
They are used in loops, so the code between the { } is done if the statement is true.
+ 1
Question is not clear. It's better if u can provide example.
It can be an Object, Scope (code block) and etc..
+ 1
thnx....i got it now.