Multiple variables declaration in ejs

25k Views Asked by At

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?

2

There are 2 best solutions below

2
Trott On BEST ANSWER

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

<% var scale_text, scale_image; %>
<% scale_text = scale_image = 'free_transform'; %>
0
Meeker On

What your writing will declare scale_text as an empty variable.

To work the way you want it to you need to do the following

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

However this is probably preferable

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