Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

only call console.log when window.console exists #14007

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/angular.bind.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
if (window.angular.bootstrap) {
//AngularJS is already loaded, so we can return here...
console.log('WARNING: Tried to load angular more than once.');
if (!!window.console) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not if (window.console)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's personal preference. I prefer to test if something is true rather than truthy ; !!window.console is a boolean while window.console is something

I don't think it has any impact on anything so if you prefer if (window.console) i'll change it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are doing !! then you are still relying on console being truthy though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but my if is testing a boolean, not a something that is truthy or falsy

when i read this code

var foo, bar;
...
if (foo) { ... }
if (!!bar) { ... }

I assume foo is a boolean while bar is a something

as i said it's just personal preference


fun fact with momentjs, moment.duration(0) is truthy while being equal to 0

moment.duration(0) == 0; // true
moment.duration(0) === 0; // false
!!moment.duration(0); // true
!!0; // false, obviously

console.log('WARNING: Tried to load angular more than once.');
}
return;
}

Expand Down