JavaScript wrong conversion of a string to a variable

This line

let dat = ('a;b\nc;d', ';');

does not do what you think. It's using the comma operator, which just returns its right operand, so it's equivalent to

let data = ';';

You could assign an array to the variable, and then spread it in the call.

relay = (dat, delimiter = ',', tested = false) =>
  dat
  .split('\n')
  .slice(tested ? dat.indexOf('\n') + 1 : 0);
let dat = ['a;b\nc;d', ';'];
console.log(relay(...dat));
console.log(relay('a;b\nc;d', ';'));
Answer:1
function log(s1, s2) {
  console.log(s1, s2);
}

let str1 = 'a';
let str2 = 'b';
log(str1, str2); // 'a' 'b'

let str = ('a', 'b');
console.log(str); // 'b'
log(str); // 'b' undefined

Notice that you cannot assign two value to one variable and use it to pass as arguments to a function. To achieve what you want, you can either use two variables, one for dat and one for delimiter, call the function with these two variables.

let dat = 'a;b\nc;d';
let delimiter = ';';
console.log(relay(dat, delimiter));

Another way is to use an object with multiple properties, e.g.

relay = ({ dat, delimiter = ',', tested = false }) => {
  dat
    .split('\n')
    .slice(tested ? dat.indexOf('\n') + 1 : 0);

  return dat;
}

let config = {
  dat: 'a;b\nc;d', 
  delimiter: ';'
};
console.log(relay(config));
Answer:2

You've defined dat:

let dat = ('a;b\nc;d', ';');

You should try to print dat, so you can see what it looks like:

console.log(dat);

You will see that dat is ';' - this is because of the relatively obscure comma operator, which simply selects the value after the last comma. In your case, ';' occurs after the last comma.

Answer:3

EDIT: I have to make this work on IE11 I have the following code: span.classList.add(span.textContent === '\ ' ? 'char' : 'spaceChar') It is working fine, but I would like to add 2 classes in case ...

EDIT: I have to make this work on IE11 I have the following code: span.classList.add(span.textContent === '\ ' ? 'char' : 'spaceChar') It is working fine, but I would like to add 2 classes in case ...

  1. javascript pass operator as parameter
  2. javascript pass operator to function
  3. javascript pass operator
  4. js pass operator as argument

I am facing problem to format the output as days/mon/years i.e ( 25/08/2019) when I add 5 days with the current date in momentjs. console.log( moment().add(5, 'days').calendar()); Output: Sunday ...

I am facing problem to format the output as days/mon/years i.e ( 25/08/2019) when I add 5 days with the current date in momentjs. console.log( moment().add(5, 'days').calendar()); Output: Sunday ...

  1. days current affairs
  2. days(current date) in db2
  3. days current cast
  4. days(current date)
  5. days(current timestamp)
  6. days current year
  7. how to calculate days with current date in excel
  8. how to add days with current date in java
  9. how to add days with current date in php
  10. how to add days with current date in jquery

In the JavaScript chaijs testing library it is possible to chain members like this: pm.expect (entry.NAME).to.be.a('string').that.is.not.empty; This question is not about the testing library, but ...

In the JavaScript chaijs testing library it is possible to chain members like this: pm.expect (entry.NAME).to.be.a('string').that.is.not.empty; This question is not about the testing library, but ...

<mat-option class="select-bank-option mat-option ng-star-inserted mat-selected mat-active" role="option" data-cy="selectDKCAD" tabindex="0" id="mat-option-261" aria-disabled="false" aria-selected="...

<mat-option class="select-bank-option mat-option ng-star-inserted mat-selected mat-active" role="option" data-cy="selectDKCAD" tabindex="0" id="mat-option-261" aria-disabled="false" aria-selected="...