Use Unary Negation on string value in JavaScript

Description

The following code shows how to use Unary Negation on string value.

Example


<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var aString = new String("36");
answer = -aString;<!--from www.  j  a  v  a 2 s  .c om-->
document.write("answer = ",answer);
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Use Unary Negation on string value in JavaScript
Home »
  Javascript Tutorial »
    Operator »
      Logic
Javascript Tutorial Logic
Use Equal Operator and if Statement in Java...
Use Unary Negation on string value in JavaS...
Use and operator to calculate booean value ...
Use and operator with boolean value in Java...
Use and operator with if statement in JavaS...
Use logical NOT to control while loop in Ja...
Use not operator with string value in JavaS...
Use or operator in if statement in JavaScri...