JS Strict Data Types - String

Tagged:  

Back to Main Documentation Page
The JS Strict Data Types String method allows you to define a variable as a String data type and maintain the value as a String.

To identify a variable as a String you would write the below code (where OptionalStringValue is some String value, if no value is inserted then an empty string is returned).

MyVar1 = new String(OptionalStringValue);

To return the data type of the String you would use the DataType property.

alert(MyVar1.DataType);

To set the value of the String to a new value you would use the below code (where StringValue is some String value).

MyVar1.Set(StringValue);

To get the value of a String you would use the value property (the below would display the value).

alert(MyVar1.value);

To append a String value to the String you would use the append method as seen below (where StringValue is some String value).

MyVar1.append(StringValue);

To compare if a String is equal to the String value you would use the CompareEq method as seen below (below is how you would use the CompareEq method in an if statement, where StringValue is some String value).

if(MyVar1.CompareEq(StringValue)){
    alert("Statement is Equal");
{

To compare if a String is not equal to the String value you would use the CompareNotEq method as seen below (below is how you would use the CompareNotEq method in an if statement, where StringValue is some String value).

if(MyVar1.CompareNotEq(StringValue)){
    alert("Statement is not Equal");
{

Below is an example of how you would use a function to maintain a String value.

function TestFunction(MyVar1){
    //Set the Data Type of each Variable
    MyVar1 = new String(MyVar1);
    alert("MyVar1 = " + MyVar.value);
}