Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

=+ javascript

let a = 2;
let b = 'hello';

console.log(a += 3); // addition
// expected output: 5

console.log(b += ' world'); // concatenation
// expected output: "hello world"
Comment

+ 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 :: post nodejs 
Javascript :: how to call a function javascript 
Javascript :: using mongoose with node js 
Javascript :: factory function in javascript 
Javascript :: pass array as function argument javascript 
Javascript :: bot react message with custom emoji 
Javascript :: react native image slider 
Javascript :: javascript sleep 1 sec 
Javascript :: switch statement js 
Javascript :: datatable ajax reload 
Javascript :: how to check if an element already exists in an array in javascript 
Javascript :: console.log is not a function 
Javascript :: props 
Javascript :: js append html in div after 
Javascript :: javascript multiple startswith 
Javascript :: passport js npm 
Javascript :: js oop 
Javascript :: Sort Date string in javascript 
Javascript :: what is a node 
Javascript :: timer js 
Javascript :: javascript reverse array and separate by spaces 
Javascript :: react native how to pass id from list to function 
Javascript :: move li to bottom of list jquery selected value 
Javascript :: MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms 
Javascript :: include antoher file wagger 
Javascript :: coindeskapi ethereum 
Javascript :: jquery to javascript converter online 
Javascript :: convert to jsx 
Javascript :: convert jquery code to javascript online 
Javascript :: node-google-spreadsheet color border 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =