Javascript Operators Flashcards

1
Q

Assign values to variables and add them together:

x = 5, y = 2, calculate z = x + y, and display z:

The assignment operator (=) assigns a value to a variable.

The addition operator (+) adds numbers:

The multiplication operator (*) multiplies numbers.

A
script>
var x = 5;
var y = 2;
var z = x + y;
document.getElementById("demo").innerHTML = z;
/script>

var x = 10;

var z = x + y;

var z = x * y;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic on numbers:

Addition
Subtraction
Multiplication
Exponentiation 
Division
Modulus (Division Remainder)
Increment
Decrement
A
\+	Addition
-	Subtraction
*	Multiplication
**	Exponentiation (ES2016)
/	Division
%	Modulus (Division Remainder)
\++	Increment
--	Decrement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

JavaScript Assignment Operators
Assignment operators assign values to JavaScript variables.

The addition assignment operator (+=) adds a value to a variable.

A
script>
var x = 10;
x += 5;
document.getElementById("demo").innerHTML = x;
/script>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

JavaScript String Operators
The + operator can also be used to add (concatenate) strings.

The += assignment operator can also be used to add (concatenate) strings:

When used on strings, the + operator is called the concatenation operator.

Adding Strings and Numbers
Adding two numbers, will return the sum, but adding a number and a string will return a string:

A
script>
var txt1 = "John";
var txt2 = "Doe";
document.getElementById("demo").innerHTML = txt1 + " " + txt2;
/script>

var txt1 = “What a very “;
txt1 += “nice day”;
What a very nice day

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Adding Strings and Numbers
Adding two numbers, will return the sum, but adding a number and a string will return a string:

The result of x, y, and z will be:

If you add a number and a string, the result will be a string!

A
script>
var x = 5 + 5;
var y = "5" + 5;
var z = "Hello" + 5;
document.getElementById("demo").innerHTML =
x + "br>" + y + "br>" + z;
/script>

10
55
Hello5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

JavaScript Comparison Operators

equal to
equal value and equal type
not equal
not equal value or not equal type
greater than
less than
greater than or equal to
less than or equal to
ternary operator
A
==	equal to
===	equal value and equal type
!=	not equal
!==	not equal value or not equal type
>	greater than
<	less than
>=	greater than or equal to
<=	less than or equal to
?	ternary operator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

JavaScript Logical Operators
logical and
logical or
logical not

A

&& logical and
|| logical or
! logical not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

JavaScript Type Operators

typeof
instanceof

A

typeof Returns the type of a variable

instanceof Returns true if an object is an instance of an object type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly