+ 1

Whats the difference between ( ) and { } I JavaScript?

18th Jul 2018, 10:28 PM
Frans
3 Answers
+ 2
Frans {} is used as a container for function or code blocks. It is also used as container for object properties. Examples: Function: function foo() { //your codes here } Code block: { //your codes here } Object: var obj = { name : "John", age : 100 } On the other hand, () is used as a container for the function or method parameters. Or as a container for the arguments that you pass to those functions or methods. Examples: Parameters: function foo(var1, var2){ return var1 + var2; } var1 and var2 are parameters of foo. Arguments: console.log(var2); var2 is an argument that you pass to the log method. Note that log() is a method of the Console object.
19th Jul 2018, 12:42 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 2
depends {} opens and closes the function here -----------------------V----- function a(var){ ------------------^------ ()means here that the function uses a var that can be defined after calling the function var+=3; alert(var); ----------^------ here the () tells what to output } a(3); ---^---- here () tells the var what to be {} and () are used in many ways, and they do not always do the same, it depends on how you are using it
18th Jul 2018, 10:57 PM
Roel
Roel - avatar
+ 1
Thanks you Roel and Jonathan Pizarra
19th Jul 2018, 8:00 AM
Frans