Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

I thought that Math.pow(2,2) was equal to 2^2 but it is not. So what does ^ (caret) mean in JavaScript?

I was executing some tests in the console but didn't recognize the results:

2 ^ 2 = 0
2 ^ 3 = 1
1 ^ 2 = 3
like image 977
Simon Edström Avatar asked Mar 19 '12 10:03

Simon Edström


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 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 a caret represent?

Definition of caret : a wedge-shaped mark made on written or printed matter to indicate the place where something is to be inserted.

What is the caret operator?

The caret is used in various programming languages to signify the XOR operator, control characters and string concatenation. It is still used in regular expressions, to mark the beginning of a line or string.


1 Answers

It means bitwise XOR.

EDIT: Fixed link

like image 153
Alexander Pavlov Avatar answered Nov 15 '22 20:11

Alexander Pavlov