JavaScript What is the difference when we use array names instead of spread operator? what difference between,what difference between can and could,what

What is the difference if I use:

var numbers = [1, 2, 3]
var mainArray = (numbers.length > 1) ? numbers : '';

instead of this:

var numbers = [1, 2, 3]
var mainArray = (numbers.length > 1) ? [...numbers] : '';
Answer:1

Since assigment of data structures points to the same space in memory, if you have two variables referencing the same array, altering one variable will alter the other. That is to say:

if x = [1, 2, 3] and y = x then we say x.push(5) y will also have that 5 because they are pointing to the same instance. If you use [...x] you are creating a copy of x. It consumes O(n) memory, a new reference. So if x is altered, y will be uneffected.

spreads are clean and neat but they do have overhead. They will effect performance if used on a very large data set.

Answer:2

The difference if you use:

var numbers = [1, 2, 3]
var mainArray = (numbers.length > 1) ? numbers : '';
//mainArray == numbers => true

Here it will assign reference of numbers to mainArray

instead of this:

var numbers = [1, 2, 3]
var mainArray = (numbers.length > 1) ? [...numbers] : '';
//mainArray == numbers => false

Here it will create new array from numbers's elements and will assign it to mainArray

Answer:3

Can anyone help me with combing jQuery Isotope filters please. In the example (CodePen Link) there are button filters at the top, and then also a text search filter underneath. Each work ...

Can anyone help me with combing jQuery Isotope filters please. In the example (CodePen Link) there are button filters at the top, and then also a text search filter underneath. Each work ...

I want to create a Uint8Array with 8 elements. I tried this var myarr = new Uint8Array(255,255,255,255,40,92,143,2); but when I run myarr.length I get back "255" when I expect the answer would be ...

I want to create a Uint8Array with 8 elements. I tried this var myarr = new Uint8Array(255,255,255,255,40,92,143,2); but when I run myarr.length I get back "255" when I expect the answer would be ...

  1. javascript initialize uint8array

Many people these days host their mongo databases on remote cloud services, how can meteor server watch the oplog for a remote database?

Many people these days host their mongo databases on remote cloud services, how can meteor server watch the oplog for a remote database?

I am building a node app where a certain wordlist is required. The wordlist is in a JSON file that looks something like this: { "en":["foo", "bar"], "gr": ["foo", "bar"] } Each key inside ...

I am building a node app where a certain wordlist is required. The wordlist is in a JSON file that looks something like this: { "en":["foo", "bar"], "gr": ["foo", "bar"] } Each key inside ...