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?
A variable declaration starts with the keyword var followed by the variable name, e.g. : var myVariable; The variable declaration ends with a semi-colon. The names of the variables in EJS-templates are case-sensitive: myVariable and myvariable are different variables.
If your variables are the same type, you can define multiple variables in one declaration statement. For example: int age, reach; In this example, two variables called age and reach would be defined as integers.
Open your text editor and type the following code, save as app. js. var express = require('express'); var ejs = require('ejs'); var app = express(); app. set('view engine', 'ejs'); app.
Basically we can declare variables in three different ways by using var, let and const keyword. Each keyword is used in some specific conditions.
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'; %>
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'; %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With