Desktop version

Main > Knowledge Base > Best practices > Code conventions > Using 1C:Enterprise script clauses > Initializing local variables in advance > Best practices > Code conventions > Using 1C:Enterprise script clauses > Initializing local variables in advance > Best practices > Code conventions > Using 1C:Enterprise script clauses > Initializing local variables in advance

Initializing local variables in advance

This article describes the standards that apply to local variable initialization. All of the listed recommendations are mandatory unless noted otherwise.

This recommendation is optional

When a script fragment calculates one or several local variable values, we recommend that you initialize the variables in advance, in order to avoid runtime errors that appear when the variable value is Undefined but the script expects a value of specific type.

Incorrect

If Something Then
    MyVariable = 10;
ElsIf
    // more branches
    …
EndIf;
 
… = MyVariable; // if Something is not TRUE, MyVariable might be Undefined

Correct:

MyVariable = 0; // default value
 
If Something Then
    MyVariable = 10;
ElsIf
    // more branches
    …
EndIf;
 
… = MyVariable;  // the variable value is always a number

This recommendation makes sense for long If / ElsIf / Else blocks where variable initializations inside the blocks might be easily overlooked.


Next page: Limitations to usage of the Goto operator




© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.