1 c,c++,java,php can tolerate the comma at the end.
When an array is assigned to a C,c++,java, the comma at the end of the last element is optional. The following two lines of code are equivalent to these languages.
int a[] = {1,2,3}; /* correct
/int a[] = {1,2,3,}//* correct * *
PHP also inherits the features of C, and the following two lines of code are equivalent.
$a = array (1,2,3); /* Correct
/$a = array (1,2,3,);/* Correct */
2 JavaScript sees the end comma as a syntax error!
However, in JavaScript, the situation is very different, the last element must not have a comma at the end, otherwise it is a grammatical error.
var a = new Array (1,2,3); Correct
var a = new Array (1,2,3,);//Error
For an object, there is also no trailing comma.
var o = {name: ' Zhao ', age:12}; Correct
var o = {name: ' Zhao ', Age:12,};//Error
Although some browsers do it with the greatest tolerance after detecting this error, this is not a uniform behavior. IE series browsers do not tolerate such mistakes.
3 JSON also can't tolerate the comma at the end
{"Name": "Zhao", "Age": 12}//correct JSON format
{"name": "Zhao", "Age": 12,}//Bad JSON format
It should be noted that JSON is a common data format, regardless of the specific programming language. Various languages use varying degrees of tolerance when decoding JSON. PHP's Json_decode () cannot tolerate the comma at the end.
Json_decode ({"Name": "Zhao", "Age": 12,}); Parsing can cause errors
About the C/c++,java,php,javascript,json array, object assignment when the last element can be followed by a comma knowledge of the small series to introduce so many people, I hope to help you, for more information please login Cloud Habitat Community website to learn more!