4. Working with operators

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What comparison operator do we use for checking to see if something is not equal to sg else.

!== or !===

What are the symbols of the arithmetic operations?

+ Addition - Subtraction * Multiplication / Division % Modulus ++ Increment -- Decrement

What are the assignment operators?

= += -= *= /= %=

examples of single operator

= assignment operators, += string operators ++ unary operators,

What are the 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

What is a binary operator?

A binary operator requires two operands, one before the operator and one after the operator: operand1 operator operand2

What is a unary operator?

A unary operator requires a single operand, either before or after the operator: operator operand or operand operator

What are the logical operators?

AND or OR. ampersand or pipe. && = ampersand || = piple

ARITHMETIC OPERATORS

ARITHMETIC OPERATORS

ASSIGNMENT OPERATORS

ASSIGMENT OPERATORS

What data type will yield if we add two numbers?

Adding two numbers, will return the sum,

COMPARISON OPERATORS

COMPARISON OPERATORS

CONDITIONAL OPERATOR

CONDITIONAL OPERATOR

What are comparison operators for?

Comparison and Logical operators are used to test for true or false.

Where do we use comparison operators?

Comparison operators can be used in conditional statements to compare values and take action depending on the result:

What are the 2 ways of using assignment operators? shorthand

Example Same As x = y x += y x -= y x *= y x /= y x %= y

What is the result in result = (5+5)*10; ?

In this case, I would take the 5+5 and that would make sure that that was executed independently. Then we multiply it by 10, and the result is 100

What is operator precedence with arithmetic operators?

It simply means that some operator symbols are treated as more important than others.

LOGICAL OPERATORS

LOGICAL OPERATORS

What is the logical operator for?

Logical operators are used to determine the logic between variables or values.

OPERATOR PRECEDENCE

OPERATOR PRECEDENCE

What is more important? multiplication and division or addition and subtraction or addition?

Particularly multiplication and division are regarded as more important than addition or subtraction.

STRING OPERATORS

STRING OPERATORS

What is a string operator?

The + operator can also be used to concatenate (add) strings. When used on strings, the + operator is called the concatenation operator.

What is the short hand for the string operator?

The += operator can also be used to concatenate strings:

When do we use ternary operator?

The ?: operator can be used as a shortcut for an if...else statement. It is typically used as part of a larger expression where an if...else statement would be awkward.

what is syntax of the ternary operator?

The syntax is condition ? result1 : result2;.

What is double ampersand sign for?

This means "and,"

what are the benefits of white space being insignificant in JS?

We can organise our code in a more readable form.

What type of operations do we use arithmetic operators for?

We have addition, we have subtraction, an asterisk for multiplication, forward slash for division.

How does js compare two values?

When comparing a string with a numeric constant, JavaScript will treat the number as a string when doing the comparison. The result of this is commonly not the same as a numeric comparison.

what is the less than or equal to comparison operator?

a <= b a is less than or equal to b.

what is the less than comparison operator?

a <b

What is the shorthand for increasing the value of a variable with 1?

a = a + 1; a += 1; a++;

what is the greater than comparison operator?

a > b if a is greater than

What is the greater than or equal to comparison operator?

a >= b

What is the classic mistake of programmers in any C-based language?

accidentally use a single equal sign where you meant to use a double equal sign.

What type of operators are there in JS regarding their functions?

arithmetic operators assignment operator String Operators comparison operators logical operators

why are they called unary operators?

because they work on one operand. e.g. a++ ++a

on how many elements does binary operator work on?

binary operators work on two elements 5 +5

What data type will yield if we add a number and a string?

but adding a number and a string will return a string: the rule is: If you add a number and a string, the result will be a string!

What is the syntax of the ternary operator?

condition ? result1 : result2; in other words test ? expression1 : expression2;

example of a not single operator

conditional operator boolen expression ? expression 1 : expression2;

Which operator is a ternary operator?

conditional operator.

What is the equivalent of AND?

double ampersand &&

What kind of comparison operator is ==? what do we call it?

equality operator

What is expression 1 in a ternary operator?

expression1 An expression returned if test is true. May be a comma

What is expression 2 in a ternary operator?

expression2 An expression returned if test is false. More than one expression may be a linked by a comma expression.

What is the strict equality operator for?

if i compare a string with a number like below they will be equal to each other when i use the double equal sign if i use the strict equality operator they will not be regarded equal.

When do we need logical operators?

if i want to check two or more conditions at the same time we need the logical operators.

In which part of the code do we always use operation.

in statements.

When do we use the double vertical sign or pipe symbol?

instead of OR we use ||

What does comparison operators evaluates to?

it always evaluates to true or false.

Where can we use incrementing and decrementing operator?

it can be used either after the variable name or before the variable name, so a++ or ++a. ++a; or a++;

What can the === recognise which the == can not?

it can recognize the type of the data. it can distinguish between strings, numbers and so on.

What is the opposite of ===?

it is !===.

What is single operator?

it is made up of one element. it does not matter how many operands are involved.

What process do we call an operation?

it is moving data from one place to another, adding or subtracting.

What is the function of a single equal sign in an operation?

it is the assignment operator. It is not a polite description; that's a command. We are setting a value. We are assigning.

Why do we do that?

it makes the code more readable.

can you save the result of an if statement into a variable as you can do it with a ternary operator?

no. in an if statement you have to save everything in the code block or echo them to the browser.

What types of camparison are there in js?

numeric comparison string comparison

So what operation do we carry out with = and with ==?

one equal sign is assignment. You are telling. Two equal signs is the equality operator. you are asking.

What is a ternary operator?

one special ternary operator, the conditional operator. requires 3 operands.

What version of unary operators do we speak about if ++ is before the variable?

prefix unary operator

What is the shorthand for score = score + 10;

score += 10;

how else can we class operators based on the number of the operands in the operation ?

single and ternary (egy vagy több részből álló operator) binary or unary or ternary operator (egy vagy több operand involved. )

how else can we class operators based on the number of the elements of the operator in the operation?

single operator not single operator (multipart operator)

how do we distinguish between operators?

single operator or ternary operator (it is made up of one element ore more elements) binary operator or unary operator (it works with one or more operands)

How many operands do the ternary operator take?

ternary operators take three operands.

What is the role of the test or condition in a ternary operator?

test is is any Boolean expression. it tests if the boolean expression evaluates to true or false.

What is the modulus arithmetic operator?

the % sign is the modulus or remainder operator. it calculates what remains from sg.I set that equal to year % 4. The % here is the modulus, or remainder operator. What it means is divide the variable year, 2003, by 4, but don't give me the result, give me the remainder, which in this case 4 would go into year 500 times and the remainder would be 3, and you will run into this one now and then.

What is the most common operator?

the arithmetic operators.

What is going to happen if we use single equal sign instead of double equal sign?

the single equal sign is a command. it does not compare the operands but assigns one to the other.

What is the name of the three equal signs?

the strict equality operator.

What is the other equality operator is there in JS?

the three equal signs.

what type of operator is the incrementing and decrementing operators

they are called unary operators.

How do we use the multiple sets of parentheses with logical operators?

they are not necessary but they can make it a bit more explicit about what we are looking at, But as ever, the entire condition, the wider set of parentheses must evaluate as either true or false.

what do the operators look like?

they are symbols that we are using to manipulate our values.

Why do we need operators?

to be able to perform addition and subtraction multiplication and division and other operations.

example of the shorthand of the string operator

txt1 = "What a very "; txt1 += "nice day"; The result of txt1 will be: What a very nice day

example of the string operator

txt1 = "What a very"; txt2 = "nice day"; txt3 = txt1 + txt2; The result of txt3 will be: What a verynice day

on how many elements does unary operator work on?

unary operators work on one element. 5++ ++5

example of ternary operator

var b=5; (b == 5) ? a="true" : a="false";

example of modulus

var x = 5; var y = 2; var z = x % y;

example of arithmetic operation

variable + 5

shorthand for arithmetic operation with assignment

variable += 5;

example of assignment

variable = 5;

example of arithmetic operation with assigment

variable = variable +5;

shorthand for arithmetic operation (+1) with assigment

variable++; or ++variable;

How can we impose an order (sorrend) in the operations of arithmetic operators?

we can use parentheses to surround the important pieces that I want to be executed together.

What is the assignment operator for?

we use it when we assign a value to a container.

how can we make sure that numeric comparison will be carried out?

we use number() function to convert string to number. if (Number(age) < 18) text = "Too young";

What elements do we use to carry out operations?

we use operators.

when do we use the same variable on both sides of the same equal sign?

when we want to update the value of the cotainer on the left and we do not want to replace it. score = score +10; In this case, we are just adding 10 to the variable called score and storing the result back in score.

What are the 2 ways of using assignment operators? regular

x = y x = x + y x = x - y x = x * y x = x / y x = x % y

Can you organise several conditions across multiple lines?

yes. If you have several things to check, you may even split it across multiple lines.

can you assign the result of the ternary operator to a variable?

yes. var greeting = "Good" + ((now.getHours() > 17) ? " evening." : " day.");


Set pelajaran terkait

8 - Life Insurance Premiums, Proceeds and Beneficiaries

View Set

Algebra 2- General Equation of a Line

View Set

Unit 1: Mental/Social/Emotional Health

View Set

Unit 1, Lesson 3-Sociological Theories

View Set