Polly po-cket
/ /

XtScript: Delete

Delete command are used to un-declared a variable

Delete is a command in XtScript to unset or remove a variable declaration.

Delete can be declared using two keywords:
del
delete

However because del is simply shorter, we will use it along our examples.

Learn XtScript Delete command from examples

Use delete to unset a variable

- Code:
<!--parser:xtscript-->
	var $content = Television, aquarium, and motorcycle.

	print <p>Before deleted: My house is filled with <b>$content.</b></p>

	# Now delete the $content variable
	del $content

	print <p>After deleted: My house is filled with <b>$content</b></p>
<!--/parser:xtscript-->
- Result:

Before deleted: My house is filled with Television, aquarium, and motorcycle.

After deleted: My house is filled with

delete are not removing the value of a variable, but it is removing the variable itself. This will make the deleted variable return false.

delete are used to un-declared a variable

- Code:
<!--parser:xtscript-->
	var $title = The Moon and The Sun
	var $question = What is my poem title?
	var $forget = Sorry, I forget the title.

	print <p>I wrote a poem "$title"</p>

	# XtScript if conditional operator
	if $title
		print <p>$question It is $title</p>
		else
			print <p>$question $forget</p>
	endif

	# Deleting the $title variable
	del $title

	if $title
		print <p>$question It is $title</p>
		else
			print <p>$question $forget</p>
	endif
<!--/parser:xtscript-->
- Result:

I wrote a poem "The Moon and The Sun"

What is my poem title? It is The Moon and The Sun

What is my poem title? Sorry, I forget the title.

We can learn more about XtScript if conditional operator later in the next chapters.