# Javascript Conflicts

**URL:** <https://boards.straightdope.com/t/javascript-conflicts/623453>\
**Category:** Factual Questions\
**Created:** [May 29, 2012, 5:07pm UTC](https://boards.straightdope.com/t/javascript-conflicts/623453 "2012-05-29T17:07:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eutychus](https://avatars.discourse-cdn.com/v4/letter/e/a3d4f5/32.png) [@Eutychus](https://boards.straightdope.com/u/Eutychus)\
**Post date:** [May 29, 2012, 5:07pm UTC](https://boards.straightdope.com/t/javascript-conflicts/623453/1 "2012-05-29T17:07:11Z")

</div>

In one project I’m working on I’m apparently having javascript conflicts … at least that my working theory. I have two scripts running … both load correctly and work well one. But once a function on one script is triggered the other script stops working.

Is there an easy way to identify where the conflict is coming from?

---

<div class="post-metadata">

**Author:** ![Athena](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@Athena](https://boards.straightdope.com/u/Athena)\
**Post date:** [May 29, 2012, 5:19pm UTC](https://boards.straightdope.com/t/javascript-conflicts/623453/2 "2012-05-29T17:19:50Z")

</div>

Have you looked at the javascript error console? Anything interesting there?

Typically when I see the behavior you describe, it’s due to some sort of error in the javascript - you’re using an uninitialized variable, or trying to get to a DOM element that doesn’t exist, or some sort of syntax error.

---

<div class="post-metadata">

**Author:** ![septimus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/septimus/32/410_2.png) [@septimus](https://boards.straightdope.com/u/septimus)\
**Post date:** [May 30, 2012, 5:37am UTC](https://boards.straightdope.com/t/javascript-conflicts/623453/3 "2012-05-30T05:37:17Z")

</div>

Do the separate scripts share same-named identifiers?

Does more than one script call setTimeout() ?

(Disclaimer: I know Javascript barely well enough to have gotten my own simple scripts to work.)

---

<div class="post-metadata">

**Author:** ![Kinthalis](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/kinthalis/32/16084_2.png) [@Kinthalis](https://boards.straightdope.com/u/Kinthalis)\
**Post date:** [May 30, 2012, 5:29pm UTC](https://boards.straightdope.com/t/javascript-conflicts/623453/4 "2012-05-30T17:29:48Z")

</div>

Chrome and firefox offer a javscript console you can enable which will allow you to see any exceptions javascript is throwing.

You can also use things like alerts to act as breakpoints, allowing you to find where the javascript bombs.

Some IDE’s will have breakpoints and other debugging tools available as well.

---

<div class="post-metadata">

**Author:** ![Blakeyrat](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@Blakeyrat](https://boards.straightdope.com/u/Blakeyrat)\
**Post date:** [May 30, 2012, 11:04pm UTC](https://boards.straightdope.com/t/javascript-conflicts/623453/5 "2012-05-30T23:04:30Z")

</div>

> [@Eutychus](#):
>
> In one project I’m working on I’m apparently having javascript conflicts … at least that my working theory. I have two scripts running … both load correctly and work well one. But once a function on one script is triggered the other script stops working.
> 
> Is there an easy way to identify where the conflict is coming from?

Most (all?) modern browsers have pretty full-featured JavaScript debuggers now. As other people mentioned, you can start by looking for uncaught exceptions, although that might not necessarily explain the conflict.

If that doesn’t help, you can set a breakpoint and step through the script that stops working to determine where exactly it stops, at which point the “why” it stopped should hopefully be obvious.

My guess is that both scripts are trying to define/use the same variable in the global namespace. A lot of UI scripts (like jQuery for example) like to use the $ variable name, and aren’t compatible with each other for that reason.
