In javascript, why [1,2]+[3,4] is not equal to [1,2,3,4]?

Someone asked on stackoverflow: arrays – Why does [1,2] + [3,4] = “1,23,4” in Javascript? Question I want to append an array to the back of another array, so I wrote the following code in firebug: [1,2] + [3,4] However, unexpectedly, it output: “1,23,4” What I expected was not output: [1,2,3,4] What is going on? ? Why is [1,2] + [3,4] not equal [1,2,3,4]? Answer Javascript’s + operator has two goals: Add two numbers Add; Concatenate the two strings. The example does not define the behavior of the + operator on arrays, so Javascript first converts the array into a string, and then perform + operations on the string. If you want to connect two arrays, you can use the concat method of the array: [1, 2].concat([3, 4 ]) // [1, 2, 3, 4] Overview of the + operator in Javascript Javascript has 6 built-in data examples: ( Translation note: Judging from the connections given, the original author’s meaning should be the data type of the original type system. Javascript actually has two types of systems. The first type system uses typeof to identify it, called the primitive (primitive) paradigm system, and the second set of paradigm systems is based…

The difference between =,==,=== in JavaScript

= and ==,=== in js are two different concepts The first thing we come into contact with in js is definitely &# 61; , from the literal meaning we can see that this is an operator that assigns the value after the equal sign to the variable before the equal sign. And the assignment operator. And and = are relational operators, and the operation result is: boolean type (true/false) == is called equality &# 61;== is called judgment of identity It is recommended to use === for comparison and judgment =&#61 ; and === Although = = and = = &#61 ; has the same functionality, but the definition of “” is very loose, allowing type conversion.The comparison of objects in Javascript is a reference comparison, not a value comparison. The object and itself are equal, but are not equal to any other objects. That is to say, two different objects have the same attribute names and attribute values, but they are still unequal.”= = =” First calculate the value of its operation, and then compare the two values ​​without any type conversion during the comparison. ==&# 61; Rules == Rules and type conversion I believe I have just started…

In JavaScript, how to conditionally add members to an object?

I can’t think of anything more idiomatic in pure Javascript than your first code snippet. However, if it’s not impossible using the jQuery library, then $.extend() should meet your requirements, because as the documentation says: Not Defined properties are not copied. So you can write: var a = $.extend({}, { b: conditionB ? 5 : undefined, c: conditionC ? 5 : undefined, // and so on…}); and get the result you expect (ifconditionB is false, then b will not exist in a).

In JavaScript, why null==0 is false and null greater than=0 is true (personal research)_javascript skills-js tutorial

In life, we are constantly writing code and writing Javascript, and we rarely have time to conduct conceptual research. As for me, I have nothing to do today, so I studied the relationship between “null” and “0”. I hope everyone can gain something from reading it. The code is as follows: alert( null>=0) The code is as follows: What will pop up in the above code? False? True? In fact, it is true. So why? Why is “null>=0” true? When null>=0, it is forced to a numeric type. When comparing null>=0, it is the answer obtained by comparing null<0. If a=b is false, if a=b is true, that is, 0<0 is false, that is, null0 is true. So null>=0 is true. The code is as follows: alert(null==0) What will pop up in the above code? False? True? In fact, it is false. “null==0” is treated specially and will not be converted to a numeric type or a numerical value. However, if the left side is a string and the right side is a numerical value, it will be converted. “null” is an object (empty object, without any properties and methods). And “0” is a number. As mentioned before, “==” does…

In JavaScript, are these two arrays the same? -php tutorial

In JavaScript, are these two arrays the same? -php tutorial

var arr1 =new Array(“Luffy”,”Zoro”,”Sanji”); var arr2 =new Array(“Cocoro”,”Qimonni”,”Kumbei”,”Iceberg”); var arr3 =new Array(“Kunis”,”Ganfulu”,”Weibo”,”Laki”); var arrAll1 = new Array(arr1,arr2,arr3); console.log( arrAll1.toString() ); arrAll2=new Array().concat(arr1,arr2,arr3) console.log( arrAll2.toString() ); Are arrAll1 and arrAll2 here the same array?? Anyway, it’s not a thing in PHP, but I don’t know if it is a thing here; But using tostring here looks the same; Response content: var arr1 =new Array(“Luffy”,”Zoro”,”Sanji”); var arr2 =new Array(“Cocoro”,”Qimonni”,”Kumbei”,”Iceberg”); var arr3 =new Array(“Kunis”,”Ganfulu”,”Weibo”,”Laki”); var arrAll1 = new Array(arr1,arr2,arr3); console.log( arrAll1.toString() ); arrAll2=new Array().concat(arr1,arr2,arr3) console.log( arrAll2.toString() ); Are arrAll1 and arrAll2 here the same array?? Anyway, it’s not a thing in PHP, but I don’t know if it is a thing here; But using tostring here looks the same; Obviously different. arrAll1 is a two-dimensional array, arrAll2 is a one-dimensional array You will know when you visit: arrAll1[0][0]; // “Luffy” arrAll2[0]; // “Luffy” The answers are the same, but you will find that they have some differences, as follows: arrAll1.length; //The result is 3 arrAll2.length; //The result is 11 This is the difference, the first one just puts the three arrays together,while the second one does take out each element of the three arrays separately and puts them into arrAll2

In javascript, what type is NaN?

The NaN attribute represents a “not a number” value. This special value is caused by an operation that cannot be performed, either because one of the operands is not a number (for example, “abc” / 4), or because the result of the operation is not a number (for example, the divisor to zero). (Recommended tutorial: js tutorial) First of all, although NaN means “not a number”, its type is Number. console.log(typeof NaN === “number”); // logs “true” Also, NaN and any Comparing something – even itself, results in false: console.log(NaN === NaN); // logs “false” If you want to test whether a number is equal to NaN, you can use value !== value. Only yields true if the value is equal to NaN. Also, ES6 provides a new Number.isNaN() function, which is a different function and more reliable than the old global isNaN() function. The above is in Javascript, what type is NaN? For more details, please pay attention to other related articles on 1024programmer.com!

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索