JavaScript Operators

With JavaScript, a number is just a number (unlike in Python where you have integers, float and complex numbers).

The operators that can be used with numbers in JavaScript are:
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (the remainders from division).

Note: if you say:
var x = 5
var y = 3
x + y  = 8

But if you say:
var "x" = 5
var "y" = 3
x + y = 53

In the latter, it returns 53, because you have defined x and y as strings by placing them in quotation marks.

There are other special variable operators: 
++ (This will increment the variable by 1): x = 5... x ++ = 6
-- (This will decrease the variable by 1): x = 5... x-- = 4

Comparisons:
== (equal to)
=== (equal value and type) this is unique to Javascript, and will return if the var is equal in number and type.  For example, if  you ask if "5" === 5, it will return 'false' as one is a string and the other is a number. However, if you ask if "5"==5, it will return 'true' despite the fact that they are different types.
!= (not equal to)
!== (not equal value or not equal type)
> (greater than)
>= (greater than or equal to)
< (less than)
<= (less than or equal to)

See about JavaScript logical operators at https://jamesymcjamesface.blogspot.com/2020/04/javascript-logical-operators-and-boolean.html

No comments:

Post a Comment

Web Development: Organizing Files and Folders

When you begin to build your website, it's a very clever idea to organize  your files and folders efficiently. You should have: A ...