Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the ^ (caret) symbol do in JavaScript?

I have some JavaScript code:

<script type="text/javascript"> $(document).ready(function(){   $('#calcular').click(function() {     var altura2 = ((($('#ddl_altura').attr("value"))/100)^2);     var peso = $('#ddl_peso').attr("value");     var resultado = Math.round(parseFloat(peso / altura2)*100)/100;     if (resultado > 0) {       $('#resultado').html(resultado);       $('#imc').show();     };   }); }); </script> 

What does the ^ (caret) symbol mean in JavaScript?

like image 834
Torres Avatar asked Sep 01 '10 13:09

Torres


People also ask

What is the use of caret symbol in JavaScript?

The caret serves two different purposes. It is a special character that denotes “the beginning of a line” and it is a “not” operator inside of [] s. Matches any character that is not a vowel followed by any number of characters. Matches a vowel at the start of a line, followed by any number of characrters.

What is caret symbol used for?

Carets are used in proofreading to signal where additional words or punctuation marks should be added to a line of text.

What does carat mean in JavaScript?

The bitwise XOR operator is indicated by a caret ( ^ ) and, of course, works directly on the binary form of numbers. Bitwise XOR is different from bitwise OR in that it returns 1 only when exactly one bit has a value of 1.

What does caret mean?

A caret is another name for a cursor. 2. Alternatively referred to as the circumflex, the caret is the symbol ( ^ ) above the 6 key on a standard United States qwerty keyboard. In mathematics, the caret represents an exponent, such as a square, cube, or another exponential power.


1 Answers

The ^ operator is the bitwise XOR operator. To square a value, use Math.pow:

var altura2 = Math.pow($('#ddl_altura').attr("value")/100, 2); 
like image 132
Gumbo Avatar answered Oct 02 '22 17:10

Gumbo