+ 1
Whats the difference between ( ) and { } I JavaScript?
3 odpowiedzi
+ 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.
+ 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
+ 1
Thanks you Roel and Jonathan Pizarra