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 :: settimeout es6 
Javascript :: $(document).ready | document.ready 
Javascript :: history.push in nextjs 
Javascript :: electron remove cors 
Javascript :: javascript keypress backspace not working 
Javascript :: random index js 
Javascript :: npm ERR! path node_modules/node-sass 
Javascript :: angular moment 
Javascript :: wp_enqueue_script bootstrap 5 
Javascript :: javascript-find-json-value 
Javascript :: get collection in ascending order firestore 
Javascript :: make circle html canvas 
Javascript :: how to reset form after submit using jquery and ajax 
Javascript :: npm react hook form 
Javascript :: display none using jquery 
Javascript :: js onclick open the phone application 
Javascript :: detect if scrolled to bottom 
Javascript :: react router how to go back 
Javascript :: change onclick attribute with javascrip 
Javascript :: js sleep sync 
Javascript :: for elem in list javascript 
Javascript :: delegate jquery 
Javascript :: jquery add remove class clicked element 
Javascript :: generate random numbers in js 
Javascript :: remove hidden attribute in js 
Javascript :: js remove duplicates from array 
Javascript :: plusieurs style sur un element javascript 
Javascript :: jest reset spy 
Javascript :: react router external link 
Javascript :: typescript prevent node modules 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =