1 c,c++,java,php can tolerate the comma at the end.
When assigning a value to an array in 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}; /* 正确 */int a[] = {1,2,3,}; /* 正确 */
PHP also inherits the characteristics of C, the following two lines of code are equivalent.
$aarray(1,2,3/* 正确 */$aarray(1,2,3/* 正确 */
2 JavaScript view end comma is 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 syntax error.
varnewArray(1,2,3//正确varnewArray(1,2,3//报错
For an object, you also cannot have a comma at the end.
var o = { name:‘赵‘, age:12// 正确var o = { name:‘赵‘, age:12// 报错
Although some browsers implement the maximum tolerance after detecting this error, this is not a uniform behavior. IE series browsers do not tolerate this error.
3 JSON also does not tolerate the comma at the end
{"name":"zhao""age":12} // 正确的JSON格式{"name":"zhao""age":12,} // 错误的JSON格式
It is important to note that JSON is a common data format that is independent of the specific programming language. Various languages also use different levels of tolerance when decoding JSON. PHP Json_decode () will not tolerate the comma at the end.
json_decode({"name":"zhao", "age":12,})// 解析会发生错误
C/c++,java,php,javascript,json array, object assignment, can the last element be followed by a comma?