<?xml version="1.0" encoding="utf-8"?>
<!-- generator="FeedCreator 1.7.2-ppt DokuWiki" -->
<?xml-stylesheet href="/lib/exe/css.php?s=feed" type="text/css"?>
<rdf:RDF
    xmlns="http://purl.org/rss/1.0/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel rdf:about="/feed.php">
        <title>Documentation Center public:software:dazstudio:4:referenceguide:scripting:language_reference:declarations</title>
        <description></description>
        <link>/</link>
        <image rdf:resource="/lib/tpl/dazdoccenter/images/favicon.ico" />
       <dc:date>2026-04-11T19:59:04+00:00</dc:date>
        <items>
            <rdf:Seq>
                <rdf:li rdf:resource="/public/software/dazstudio/4/referenceguide/scripting/language_reference/declarations/start"/>
            </rdf:Seq>
        </items>
    </channel>
    <image rdf:about="/lib/tpl/dazdoccenter/images/favicon.ico">
        <title>Documentation Center</title>
        <link>/</link>
        <url>/lib/tpl/dazdoccenter/images/favicon.ico</url>
    </image>
    <item rdf:about="/public/software/dazstudio/4/referenceguide/scripting/language_reference/declarations/start">
        <dc:format>text/html</dc:format>
        <dc:date>2025-03-26T20:10:57+00:00</dc:date>
        <title>Declarations</title>
        <link>/public/software/dazstudio/4/referenceguide/scripting/language_reference/declarations/start</link>
        <description>
&lt;h1 id=&quot;declarations&quot;&gt;Declarations&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;/div&gt;

&lt;h2 id=&quot;variables&quot;&gt;Variables&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
A variable, with regard to computer programming, can be thought of as a place to store a piece of information, whether it varies or not. Generally speaking, a variable binds an object to an &lt;a href=&quot;/public/software/dazstudio/4/referenceguide/scripting/language_reference/identifiers/start&quot; class=&quot;wikilink1&quot; title=&quot;public:software:dazstudio:4:referenceguide:scripting:language_reference:identifiers:start&quot;&gt;identifier&lt;/a&gt; for access to that object at a later point in the code. That object can be many things, for instance: a number, a string (text), or an as yet undefined collection of information.
&lt;/p&gt;

&lt;p&gt;
Variables are declared using the &lt;code&gt;var&lt;/code&gt; keyword. If a variable has a type&lt;sup&gt;&lt;a href=&quot;#fn__1&quot; id=&quot;fnt__1&quot; class=&quot;fn_top&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt; specified, only objects of the given type should be assigned to that variable. Emphasis being on the word &lt;em&gt;should&lt;/em&gt;. As mentioned on the main page of this documentation, &lt;abbr title=&quot;Digital Art Zone&quot;&gt;DAZ&lt;/abbr&gt; Script is dynamically typed&lt;sup&gt;&lt;a href=&quot;#fn__2&quot; id=&quot;fnt__2&quot; class=&quot;fn_top&quot;&gt;2)&lt;/a&gt;&lt;/sup&gt; and as such does not prevent a variable from being assigned a type inconsistent with that which may have been specified at declaration. In fact, &lt;abbr title=&quot;Digital Art Zone&quot;&gt;DAZ&lt;/abbr&gt; Script variables are always of a type consistent with the type of value they contain.
&lt;/p&gt;
&lt;!-- EDIT1 PLUGIN_WRAP_START [0-] --&gt;&lt;div class=&quot;wrap_center wrap_round wrap_info plugin_wrap&quot; style=&quot;width: 80%;&quot;&gt;
&lt;p&gt;
&lt;strong&gt;Note:&lt;/strong&gt; If you do not initialize your variable upon declaration, that is, assign it some value, it automatically assumes the type and value &lt;code&gt;undefined&lt;/code&gt;.
&lt;/p&gt;
&lt;/div&gt;&lt;!-- EDIT2 PLUGIN_WRAP_END [0-] --&gt;
&lt;p&gt;
The scope of a variable is always an important factor to consider. The scope of a variable refers to where in the code the variable has meaning. When a variable is said to have a local or lexical scope, it means that the variable only exists, or has meaning, within a subroutine (a smaller portion of the overall program). Conversely, when a variable is said to have a global scope, it means that the variable exists such that it can be accessed from anywhere, by anything. It is considered good programming practice to make the scope of a variable as narrow as possible, to prevent different parts of a program from modifying, using or otherwise conflicting with another part&amp;#039;s variables.
&lt;/p&gt;

&lt;p&gt;
In &lt;abbr title=&quot;Digital Art Zone&quot;&gt;DAZ&lt;/abbr&gt; Script, variables declared with &lt;code&gt;var&lt;/code&gt; are local to the enclosing function. If a variable is assigned to implicitly (without being declared using the &lt;code&gt;var&lt;/code&gt; keyword), the scope chain is traversed upward until/unless a properly declared variable by the same name is encountered or ultimately the global object. While syntactically valid, implicit variables can be quite troublesome, and are typically considered to be poor form. Using variables in this manner is &lt;em&gt;not recommended&lt;/em&gt;, as it can make your code difficult to debug and maintain.
&lt;/p&gt;
&lt;!-- EDIT3 PLUGIN_WRAP_START [0-] --&gt;&lt;div class=&quot;wrap_center wrap_round wrap_info plugin_wrap&quot; style=&quot;width: 80%;&quot;&gt;
&lt;p&gt;
&lt;strong&gt;Note:&lt;/strong&gt; It is important that you always declare variables before attempting to use them. Failure to do so will result in an error from the interpreter.
&lt;/p&gt;
&lt;/div&gt;&lt;!-- EDIT4 PLUGIN_WRAP_END [0-] --&gt;
&lt;/div&gt;

&lt;h3 id=&quot;examples&quot;&gt;Examples&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Variable declared, but not initialized.
&lt;/p&gt;
&lt;pre class=&quot;code ecmascript&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;var&lt;/span&gt; sTmp&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// typeof sTmp == undefined&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// sTmp == undefined&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Variable declared and initialized.
&lt;/p&gt;
&lt;pre class=&quot;code ecmascript&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;var&lt;/span&gt; sTmp &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Temp&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// typeof sTmp == &amp;quot;string&amp;quot;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// sTmp == &amp;quot;Temp&amp;quot;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Variable declared and initialized with one type, later changing type.
&lt;/p&gt;
&lt;pre class=&quot;code ecmascript&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;var&lt;/span&gt; sTmp &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;5&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// typeof sTmp == &amp;quot;string&amp;quot;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// sTmp == &amp;quot;5&amp;quot;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// Assigned to a Number type&lt;/span&gt;
sTmp &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// typeof sTmp == &amp;quot;number&amp;quot;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// sTmp == 5&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2 id=&quot;functions_methods&quot;&gt;Functions (Methods)&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
A &lt;code&gt;function&lt;/code&gt; can be thought of as a sequence of statements (a subroutine) that performs a specific task, the same task, each time its run. Functions can be “called”, which means the “current” instruction sequence is temporarily suspended and the sequence of statements in the &lt;code&gt;function&lt;/code&gt; are executed, after which point control is passed back to the instruction sequence that made the call. This also means that same sequence of statements can be executed as many times as necessary without the need to be written in the code each time. A &lt;code&gt;function&lt;/code&gt; may take an optional set of input parameters (arguments) to parameterize that sequence, and it may also return an optional output (&lt;a href=&quot;/public/software/dazstudio/4/referenceguide/scripting/language_reference/control_statements/start#return&quot; class=&quot;wikilink1&quot; title=&quot;public:software:dazstudio:4:referenceguide:scripting:language_reference:control_statements:start&quot;&gt;return&lt;/a&gt; value).
&lt;/p&gt;

&lt;p&gt;
Functions are declared using the &lt;code&gt;function&lt;/code&gt; keyword. They can exist in the global namespace, or in the context of another object.
&lt;/p&gt;

&lt;/div&gt;

&lt;h3 id=&quot;examples1&quot;&gt;Examples&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
A simple &lt;code&gt;function&lt;/code&gt;.
&lt;/p&gt;
&lt;pre class=&quot;code ecmascript&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; myFunction&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;co1&quot;&gt;// ...statements;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
A simple &lt;code&gt;function&lt;/code&gt; with an argument.
&lt;/p&gt;
&lt;pre class=&quot;code ecmascript&quot;&gt;&lt;span class=&quot;co1&quot;&gt;// Create the function&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; showMessage&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; sMessage &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	MessageBox&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;information&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; sMessage&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Message&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&amp;amp;OK&amp;quot;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// Call the function&lt;/span&gt;
showMessage&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Hello World!&amp;quot;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
A simple &lt;code&gt;function&lt;/code&gt; with a &lt;code&gt;return&lt;/code&gt; value.
&lt;/p&gt;
&lt;pre class=&quot;code ecmascript&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; getWorldGreeting&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;kw2&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Hello World!&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;var&lt;/span&gt; sTmp &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; getWorldGreeting&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// sTmp == &amp;quot;Hello World!&amp;quot;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class=&quot;footnotes&quot;&gt;
&lt;div class=&quot;fn&quot;&gt;&lt;sup&gt;&lt;a href=&quot;#fnt__1&quot; id=&quot;fn__1&quot; class=&quot;fn_bot&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt; 
&lt;div class=&quot;content&quot;&gt;A name or label for a set of values and operations that can be performed on that set of values&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;fn&quot;&gt;&lt;sup&gt;&lt;a href=&quot;#fnt__2&quot; id=&quot;fn__2&quot; class=&quot;fn_bot&quot;&gt;2)&lt;/a&gt;&lt;/sup&gt; 
&lt;div class=&quot;content&quot;&gt;As opposed to statically typed languages, like C++&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
</description>
    </item>
</rdf:RDF>
