Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

operators in js

//Logical Binary and Ternary Operators in Javascript

== Equal to
=== Strictly equal to
!= Not equal to
!== Strictly not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

&& Logical and
|| Logical or
! Logical not

? Ternary operator
Comment

? operator in js

? call ternary operator is shorcut for, "if statement".
// below we make object with key id, and assign it a value from body.id.
// if body.id is null it will return false and it will assign it res.id value.
{ id: body.id? body.id : res.id }
// we can write it in if statement like this
if(body.id){
 return {id:body.id}
}else{
  return {id:res.id}
}
Comment

+ operator javascript

// JavaScript Unary Operators The unary plus operator (+)
// The unary plus ( + ) precedes its operand and evaluates to its operand. It attempts to convert the operand to a number, if it isn't already.

+42           // 42
+"42"         // 42
+true         // 1
+false        // 0
+null         // 0
+undefined    // NaN
+NaN          // NaN
+"foo"        // NaN
+{}           // NaN
+function(){} // NaN

// Note that attempting to convert an array can result in unexpected return values.
// In the background, arrays are first converted to their string representations:

[].toString() === '';
[5].toString() === '5';
[1, 2].toString() === '1,2';

// The operator then attempts to convert those strings to numbers:

+[]           // 0   ( === +'' )
+[5]          // 5   ( === +'5' )
+[1, 2]       // NaN ( === +'1,2' )
Comment

PREVIOUS NEXT
Code Example
Javascript :: chartjs templates 
Javascript :: how to load js in vuejs components 
Javascript :: optional function parameter javascript 
Javascript :: how to subtract time in javascript 
Javascript :: javascript some method 
Javascript :: react protected route 
Javascript :: split whitespace except in quotes javascript 
Javascript :: ng select2 angular dropdown 
Javascript :: json stringify number 
Javascript :: create a style in div jsx 
Javascript :: math random javascript 
Javascript :: adding commas after thousand 
Javascript :: jQuery intellisence in VSCode 
Javascript :: javaScript setDate() Method 
Javascript :: animate change of class angular 
Javascript :: date and time javascript 
Javascript :: how to create a object in javascript 
Javascript :: javascript array loop 
Javascript :: strict mode 
Javascript :: vs code file nesting 
Javascript :: javascript unknown number of parameters 
Javascript :: infinite scroll for chat react js 
Javascript :: what is morgan in nodejs 
Javascript :: js detect object has key 
Javascript :: convert date to ist format javascript 
Javascript :: arrow function javascript 
Javascript :: discord delete message 
Javascript :: axios post request progress 
Javascript :: stringify vs parse 
Javascript :: discord bot remove message reaction 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =