Loading...

What is the purpose of void this in the javascript function


What is the purpose of void this in the javascript function end

words = ''; wordless=' ';

function say_it(word) {
     return word ? smothered_mouthfuls(word) : end();
}

function smothered_mouthfuls(word) {
    word = words ? wordless + word : word;
    words = words + word;
    return say_it;
 }

 function end() {
     return  void this,words;
 }

Any one know void this purpose, Thanks.

- - Source

Answers

answered 1 week ago Nina Scholz #1

What you have is the voidoperator

The void operator evaluates the given expression and then returns undefined.

in combination with comma operator

The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.

return void this, words;

works like this

return (void this, words); // return words

Actually, it looks like noise to the code, without some meaning of the expression of this.

If the call of this invokes something, then it's necessary, otherwise it looks like code smell, where some code is doing something without explicit mention.

var words = '', wordless=' ';

function say_it(word) {
    return word ? smothered_mouthfuls(word) : end();
}

function smothered_mouthfuls(word) {
    word = words ? wordless + word : word;
    words = words + word;
    return say_it;
}

function end() {
    void this;     // or not
    return  words;
}
   
console.log(say_it('foo')());
console.log(say_it('bar')());
console.log(say_it('baz')());

comments powered by Disqus