Just opened a client's javascript file and the first lines are along the lines of this:
{
var s_account="blog";
}
Which I don't get. Normally, in my experience, curly braces wrap around a function...
function welcome(){ ...
...or a json JavaScript object
var attributes = { this : "that...
Can anyone tell me why there are curly braces with no text before them or after them? What does it do / what is the point of it?
It means the variable is a dictionary that stores key value pairs. The subscript or the value within the [] brackets is the key and the value on the right side is the value.
Curly braces are required around object literals and functions. The are also required around conditional statements that are more than a single line of code. You can omit them around single line conditional statements, but it is good practice (and good for readability) to use them in all cases, in my opinion.
No. Curly braces do not have to be escaped in JSON.
It's a block and completely pointless unless you label it:
block: {
var s_account="blog";
console.log("executed");
break block;
console.log("not executed");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With