I'm practicing JavaScript at the moment, I'm looking at the basics - I'm very new to JavaScript.

With that said, I'm trying to work out why I would ever use an === over a Boolean.

var moonPhase = 'full';

if (moonPhase === 'full') {
console.log('howwwlll!!')
}
else {
console.log('I swear I am not a werewolf...')
}

Thanks in advance.

Roman answered: turns out I'm not limited to true/false yes/no etc when using ===. This may seem obvious but as I said I'm still wrapping my head around the basics.

    
"...could anybody explain why I wouldn't just use a Boolean here..." Huh? What would that look like? (Side note: You are using a boolean there. The result of === is a boolean.) – T.J. Crowder 4 hours ago
    
The comparision evaluates to bool anyway... – DontVoteMeDown 4 hours ago
1  
how would you use a boolean there? – Luca Kiebel 4 hours ago
    
Okay folks, no need to downvote this into oblivion. Give the OP a chance to address the questions. – T.J. Crowder 4 hours ago
2  
@phurst: Stack Overflow is a very active place. When you post a question (or answer), stick around for a few minutes to answer questions like the ones above. – T.J. Crowder 4 hours ago

1 Answer 1

Imagine you are programming a chatbot and when the user writes "Hello" you want to answer "Hi".

// this will always execute..
if (true) {
    answere('Hi')
}

// this will only execute when input is "Hello"
if (input === 'Hello') {
    answer('Hi')
}

In many situations there isn't the possibility to just use true and false. But when you use a comparison like input === 'Hello' it will return a boolean. Try window.alert('a' === 'a') and you will see a true

1  
No downvote: as far as I understand question, this seams requested answer. – LS_ᴅᴇᴠ 3 hours ago
    
Thanks for the answer, really helped. – phurst 2 hours ago