JavaScript ValueOf

The JavaScript ValueOf function is a String function that is used to return the string. The syntax of the JavaScript ValueOf function is:


JavaScript ValueOf Function Example

The following set of examples will help you understand the ValueOf function in JavaScript Programming Language.

TIP: The ValueOf function does not accept any arguments.

<!DOCTYPE html>
    <title> ValueOf JavaScript </title>
    <h1> JavaScript ValueOf </h1>
    var Str1 = "Tutorial Gateway";
    var Str2 = "Learn JavaScript";
    var Str3 = Str1.valueOf();
    var Str4 = Str2.valueOf();
    document.write(Str3 + "<br \>");
    document.write(Str4 + "<br \>");
    if (Str3 === Str4)
        document.write(" Both are Equal <br \>");
        document.write(" Both are Not Equal <br \>");
JavaScript VALUEOF Function

The following JavaScript statement will return the value of above-declared string variables

  var Str3 = Str1.valueOf();
  var Str4 = Str2.valueOf();

Next, We used the JavaScript Else Statement to check whether the value of String variable Str1 is strictly equal to Str2 or not.