+ 2

Can any one tell what's the use of { and } in js.

23rd May 2017, 2:19 PM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar
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
23rd May 2017, 3:29 PM
Apel Mahmod
Apel Mahmod - avatar
+ 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
23rd May 2017, 2:31 PM
Eranga
Eranga - avatar
+ 1
to contain some code
23rd May 2017, 2:20 PM
Setiawan Next
Setiawan Next - avatar
+ 1
They are used in loops, so the code between the { } is done if the statement is true.
23rd May 2017, 2:25 PM
Maart
Maart - avatar
+ 1
Question is not clear. It's​ better if u can provide example. It can be an Object, Scope (code block) and etc..
23rd May 2017, 2:26 PM
Eranga
Eranga - avatar
+ 1
thnx....i got it now.
23rd May 2017, 2:39 PM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar