Help with this JS function

Help with this JS function
0

#1

I have this JS function in a layout page I’m using on a asp.net MVC website:

$(document).ready(function () {
  //Display the welcome ad
  if (@Globals.configSettings.DisplayWelcomeAd != false) {
    displayWelcomeAd('@Utility.IsBot');
  }
  SocialShareKit.init();
});

And what is happening is that @Globals.configSettings.DisplayWelcomeAd is false. It’s going and checking, and returning false, yet it still runs the code block every time. Do you have any idea why it would be doing this??


#2

According to your current code the SocialShareKit.init(); will run everytime because of where you have it after the if statement.

Or are you saying the WelcomeAd is displaying everytime too?


#3

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

Also, try to get in the habit of indenting your code to make it more readable. I cleaned up the indentation also.


#4

Does changing to strict equality checking do anything different? (from != to !==). If you console.log @Globals.configSettings.DisplayWelcomeAd what do you get?