Javascript Number Type Create a Numeric Value Using Number Literals

Description

Javascript Number Type Create a Numeric Value Using Number Literals

// Basic arithmetic 
let a = 1 + 1; /*  w  w w  . j  ava  2  s. c o m*/
console.log( typeof a );      // number 
console.log( "1 + 1 = " + a );// 1 + 1 = 2 
console.log(10 - 5.52 );      // 4.48 
console.log(3.49 / .52 );     // 6.711538461538462 
console.log(95.78 * 627 );    // 60054.06 

// Comparing integer and floating-point values 
console.log( 1 === 1.000 );   // true 
console.log( typeof 1 === typeof 1.000 );        // true 

// Scientific Notation 
console.log( 1e1 );           // 10 
console.log( 1e3 );           // 1000 
console.log(1.51e-6 );        // 0.00000151 
console.log( 1.7985e19 );      // 17985000000000000000 

// Hexadecimal Notation 
console.log( 0x01 );        // 1 
console.log( 0x1a );        // 26 
console.log( 0xbc );        // 188 
console.log( 0xff );        // 255 

// Octal Notation 
console.log( 0o1 );         // 1 
console.log( 0o32 );        // 26 
console.log( 0o274 );       // 188 
console.log( 0o377 );       // 255 

// Octal Notation 
console.log( 0b1 );         // 1 
console.log( 0b11010 );     // 26 
console.log( 0o10111100 );  // 2134592 
console.log( 0o11111111 );  // 2396745 



PreviousNext

Related