Next: , Previous: Scope, Up: Variables Overview



5.1.2 Modifiability

For both global and local variables, you can declare that the variable cannot be modified by declaring it using the const keyword rather than global or local:

         const response_script = "./scripts/nuke-em";

Note that const variables must be initialized (otherwise, of course, there's no way for them to ever hold a useful value).

The utility of marking a variable as unmodifiable is for clarity in expressing your script—making it explicit that a particular value will never change—and also allows Bro to possibly optimize accesses to the variable (though it does little of this currently).

Note that const variables can be redefined via redef.