Answers for "js or operator"

5

or in js

// The Or operator in Javascript is 2 vertical lines = ||

//Example
var firstnumber = 10;
var secondnumber = 20;

//The Or operator in action
if(firstnumber > 20 || secondnumber< 10) {
}
Posted by: Guest on May-09-2021
9

javascript and operator

//AND Operator expressed as &&

const x = 7;
const y = 4;

(x == 7 && y == 5); // false
(x == 3 && y == 4); // false
(x == 7 && y == 4); // true

if (condition == value && condition == otherValue) {
  return something;
}
Posted by: Guest on October-14-2020
6

js comparison operators

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
Posted by: Guest on January-04-2021
6

or operator in javascript

//The OR operator in Javascript is 2 verticals lines: ||

var a = true;
var b = false;

if(a || b) {
	//one of them is true, code inside this block will be executed
}
Posted by: Guest on July-25-2020
0

js or operator

// index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>js or operator</title>
  </head>
  <body>
    <h1 class="display_msg">Add</h1>
    <input type="text" name="num1" id="num1" /><br />
    <input type="text" name="num2" id="num2" /><br /><br />
    <button type="button" onclick="btnClicked()">Add</button>
    <br /><br />
    <span class="valid_details"></span>
    <script src="app.js"></script>
  </body>
</html>

// app.js
function btnClicked() {
  // value 1 and 2 from html input fields (with id 'num1' and 'num2')
  // you can also use document.querySelector
  let num1 = document.getElementById("num1").value;
  let num2 = document.getElementById("num2").value;

  // simple addition of num1 and 2 stored in 'result'
  // use innerHTML to display the results in the browser
  let result = (document.querySelector(".display_msg").innerHTML =
    Number(num1) + Number(num2));

  // some sort of validation using 'or' '||'
  if (
    num1 === "" ||
    num2 === "" ||
    num1 === 0 ||
    num1 === "0" ||
    num2 === 0 ||
    num2 === "0"
  ) {
    result = document.querySelector(
      ".display_msg"
    ).innerHTML = `Invalid Input!!!`;
    return result;
  } else {
    return result;
  }

  /*
   *  this will not print because return statement will basically end the function
   *  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
   */

  console.log(result);
}
Posted by: Guest on September-04-2021
0

js or operator

/*OR operator:*/
||

// example:
var a = 10;
var b = 5;

if(a > 7 or b > 7){ 
  print("This will print!")
}
// Even though a is not less than 7, b is, so the program will print
// the statement.
Posted by: Guest on January-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language