Is there a limit to number of if/else statements we can use in javascript code extension?

Silver Contributor
Silver Contributor
we have multiple if/else statements we are using for our success events. noticed that the if block curly brackets does not turn green when we add additional if/else statement.
2 REPLIES 2

Is there a limit to number of if/else statements we can use in javascript code extension?

Moderator
Moderator
Hi Sebastian, There is no limit; use as many as you like. However, the syntax highlighter is not perfect, and under certain conditions, it doesn't properly detect the beginning and end of certain statements. I would like to stress that this only happens very rarely. Usually, however, it is correct, and the reason it doesn't highlight the closing brace is due to a syntax error somewhere in your code. If you are absolutely sure that there is no syntax error, then it is probable that you've written some valid code that the syntax highlighter doesn't quite understand. I would advise you to proceed with caution and test your code on dev/qa before publishing to prod, just in case there is a syntax error. One thing that occasionally catches me out, is not closing the parentheses on an if statement when using a regular expression. e.g.: if (/home/.test(b.page_name) { // notice the missing parenthesis above! } Hope this helps. Feel free to share the code with me directly if you want me to review it (or send me a private message and let me know which account/profile you're using, and the name of the extension). Hope this is useful. Craig.
Check out our new Swift integration library for iOS, macOS, tvOS and watchOS: https://github.com/Tealium/tealium-swift with updated
documentation https://community.tealiumiq.com/t5/Swift/tkb-p/swift.

Is there a limit to number of if/else statements we can use in javascript code extension?

Gold Contributor
Gold Contributor
Hi Sebastian, Like Craig said, there is no limit. I currently have a client that has an extension that is over 800 lines of if/else statements, and they all work without issue. Andrew
Public