• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

dumb question? what does if (!!window.EventSource) mean?

Q&A Forum › Category: ESP32 › dumb question? what does if (!!window.EventSource) mean?
0 Vote Up Vote Down
Joe Margevicius asked 1 year ago

I can’t find what !! means in javascript (it’s in the Build WebServers book in module 3.1) ..what does if (!!window.EventSource) mean?  (double negative? … if so, why use it?)

4 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
It’s to make sure that the result of window.EventSource is converted to a boolean variable, even if it doesn’t return a boolean type.
 
Regards,
Sara

0 Vote Up Vote Down
Joe Margevicius answered 1 year ago

humm. ok. I’ll take your word on that, and obviously it works.  Strange that I can’t find any language reference that explains that operator, and I’ve never seen anything like it before.  Would you have a link to something that defines it, or parse it out a bit?  Thanks.

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
I was also confused about that. It’s the notation used by the library examples. So, we decided to keep it like that.
https://riptutorial.com/javascript/example/3047/double-negation—-x-
Regards,
Sara

0 Vote Up Vote Down
Joe Margevicius answered 1 year ago

Hi Sara, thank you for the link which nicely explains it.  It also helped me understand negation of numerical variables versus string variables:

x !== 0  // instead of !!x in case x is a number

x != null  // instead of !!x in case x is an object, string or undefined

so assuming window.EventSource is a number (it’s return value), another way to write the
statement would be: if (window.EventSource !== 0). But if it’s not a number,
it would be if (window.EventSource !=0). !! isn’t so bad after all 🙂 Thanks, and this can be closed out.

 

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.