Skip to main content
dublove
Legend
Nov 22, 2026 4:32 PM UTC
Answered

Do multiple parallel items after '===' have to be listed separately for each item?

For example, I always want to write multiple conditions like this:

if(('Rectangle' || 'Oval' || 'Polygon') == item.constructor.name)

But I found that it only recognizes the first one, or it feels a bit slow to run.
Does it have to be written like this? There is still a better way to write it:

if(
'Rectangle' === item.constructor.name
|| 'Oval'=== item.constructor.name
|| 'Polygon'=== item.constructor.name 
)

 

    Peter Kahrel
    Peter KahrelCorrect answer
    Community Expert
    Nov 23, 2026 10:42 AM UTC

    Or use a regular expression, much shorter:

    if (/Rectangle|Oval|Polygon/.test(item.constructor.name)) {
    alert(item.constructor.name);
    }

     

    14 replies

    Peter Kahrel
    Community Expert
    Peter KahrelCommunity ExpertCorrect answer
    Community Expert
    Nov 23, 2026 10:42 AM UTC

    Or use a regular expression, much shorter:

    if (/Rectangle|Oval|Polygon/.test(item.constructor.name)) {
    alert(item.constructor.name);
    }

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Nov 23, 2026 11:16 AM UTC

    Peter Kahrel's method has opened my eyes again.
    Thank you.

    Translate
    Community Expert
    Nov 23, 2026 11:20 AM UTC

    ​@dublove these are basics you should know. Your original problem was related to understanding how or works. So work on your programming basics. There are multiple ways to do things and you will mostly find new ways to do the same stuff but you need to understand what works and why

    Translate
    -Manan
    rob day
    Community Expert
    Community Expert
    Nov 22, 2026 5:39 PM UTC

    You have too many parenthesis—should be:

     

    var item = app.activeDocument.selection[0]
    if('Rectangle' || 'Oval' || 'Polygon' == item.constructor.name){
    alert(item.constructor.name)
    }

     

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Nov 23, 2026 2:40 AM UTC

    Thank you.
    I didn't expect multiple parentheses to also have an impact.

    Translate
    Peter Spier
    Community Expert
    Community Expert
    Nov 22, 2026 5:27 PM UTC

    I haven’t done any real scripting in quite some time, but this seems like a case where one would use a “case” switch.  Don’t recall if those exist in javascript.

    Translate