Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

? 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 :: pagination in b table in bootstrap vue 
Javascript :: var = {} js 
Javascript :: Material-ui account icon 
Javascript :: Create array literal 
Javascript :: how to upgrade nodejs version 
Javascript :: access object property dynamically javascript 
Javascript :: jquery plugins 
Javascript :: assertion error in jest 
Javascript :: map duplicate keys JS 
Javascript :: cross browser testing 
Javascript :: get last item in array js 
Javascript :: react variable component 
Javascript :: javascript comment 
Javascript :: react script syntax for deployment 
Javascript :: postgresql json array contains 
Javascript :: set timer 
Javascript :: edit message sent by discord.js 
Javascript :: axios async await 
Javascript :: passport jwt strategy 
Javascript :: json generator 
Javascript :: status discored jks 
Javascript :: discord.js TypeError: Reactedmsg.delete message using id 
Javascript :: remove unused javascript angular 
Javascript :: get JSON information into html control with javascript 
Javascript :: show mwssage js 
Javascript :: axios get request with nested params serialize qs 
Javascript :: javascript generator send vs next 
Javascript :: javascript remove last charcter from string 
Javascript :: js query first instance 
Javascript :: how to get the class name dynamically using jquery 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =