let obj = {
  valueOf() {
    return "2";
  }
};

alert(obj);

I thought in the absence of toString() the valueOf() will be called when a string is expected.

1

There are 1 best solutions below

9
Code Maniac On BEST ANSWER

This does not call because this find toString in prototype chain, if we create a object without any prototype it will call

let obj = Object.create(null)

obj.valueOf =
  function() {
    return "2";
  }

alert(obj);