# <var>

Description

Declares a variable in the scope of its parent element. If the `<var>` occurs in executable content, the declaration is made only when the `<var>` element is executed. If the `<var>` occurs as a child of a `<form>`, the declaration is made during the form's initialization phase. If the `<var>` occurs as a child of `<vxml>`, the declaration is made when the document is initialized (in document order). If the variable is already defined in the current scope, further declarations are treated as value assignments.

Syntax

    <var
        name="string"
        expr="ECMAScript_Expression"/>

Attributes

Attribute | Description
name | The name of the variable. Required.
expr | An ECMAScript expression to be evaluated and used as the initial value assigned to the variable. Optional. (Defaults to undefined.)

Parents

<block>, <catch>, <error>, <filled>, <foreach>, <form>, <help>, <if>, <noinput>, <nomatch>, <vxml>

Children

None.

Extensions

None.

Limitations/Restrictions

- `<var>` cannot be used as a child of `<foreach>` when `<foreach>` is a child of `<prompt>`.

Example

    <?xml version="1.0"?>
    <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
      <var name="var1" expr="'first'"/>
      <form>
        <block>
          The initial value is <value expr="var1"/>.
        </block>
      </form>
    </vxml>