Multiple variables declaration in ejs

Khawer Zeshan picture Khawer Zeshan · May 20, 2015 · Viewed 17k times · Source

I am trying to declare and assign a default value to multiple variables. But the value is only getting assigned to last variable

<% var scale_text,scale_image = 'free_transform'; %>

This print empty:

<%- scale_text %>

This prints free_transform

<%- scale_image %>

What am i missing?

Answer

Trott picture Trott · May 20, 2015

Separate the variables with = to set them to the same default value.

<% var scale_text = scale_image = 'free_transform'; %>

Update: Although, as @Meeker notes in their answer, this is probably better:

<% var scale_text, scale_image; %>
<% scale_text = scale_image = 'free_transform'; %>