June 23, 2023

JavaScript Operators

Great job on starting a new lesson! In the FAQ, test yourself by clicking the correct answer for each question. Then, click Next button at bottom right to continue.

JavaScript Operators

JavaScript operators are used to perform operations on JavaScript variables or directly on data.

What are the 4 types of JavaScript operators?

There are four types of JavaScript operators: arithmetic operators, comparison operators, logical operators, and string concatenation operators.

What are the most common JavaScript operators?

The most common JavaScript operators include addition (+), subtraction (-), multiplication (*), division (/), equality (==), strict equality (===), less than (<), greater than (>), less than or equal to (<=), greater than or equal to (>=), logical AND (&&), logical OR (||), and logical NOT (!).

JavaScript Example: Operators

// JavaScript operators examples
var num1 = 10;
var num2 = 5;
var sum = num1 + num2; // addition
var difference = num1 - num2; // subtraction
var product = num1 * num2; // multiplication
var quotient = num1 / num2; // division
var isEqual = num1 === num2; // strict equality
var isLessThan = num1 < num2; // less than
var logicalAND = (num1 > 0) && (num2 > 0); // logical AND
var concatString = "Hello, " + "Software Testing Space Viewer!"; // string concatenation
// Output results using document.write()
document.write("Sum: " + sum + '<br />');
document.write("Difference: " + difference + '<br />');
document.write("Product: " + product + '<br />');
document.write("Quotient: " + quotient + '<br />');
document.write("Is Equal: " + isEqual + '<br />');
document.write("Is Less Than: " + isLessThan + '<br />');
document.write("Logical AND: " + logicalAND + '<br />');
document.write("Concatenated String: " + concatString);

FAQ (Interview Questions and Answers)

  1. What are the four types of JavaScript operators?
    Arithmetic, comparison, logical, and string concatenation
    Unary, binary, ternary, and assignment
    Primary, secondary, conditional, and assignment
  2. Which operator is used for string concatenation in JavaScript?
    &&
    ==
    +
  3. What does the logical AND operator (&&) do in JavaScript?
    Performs a logical AND operation on two conditions
    Performs a logical OR operation on two conditions
    Negates a condition
  4. What is the result of the expression 5 > 3?
    true
    false
    undefined
  5. Which operator is used for strict equality comparison in JavaScript?
    =
    ===
    ==

Your Total Score: 0 out of 5

Remember to just comment if you have any doubts or queries.

Where to learn JavaScript? Take the JavaScript course free in Software Testing Space.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.