How to turn on a particular bit in a number ? | Returns a number that has all bits same as n except the k 'th  bit which is made 1 ; k must be greater than 0 ; Do | of n with a number with all unset bits except the k 'th bit ; Driver Code
function turnOnK ( n , k ) { if ( k <= 0 ) return n ; return ( n | ( 1 << ( k - 1 ) ) ) ; } let n = 4 ; let k = 2 ; document . write ( turnOnK ( n , k ) ) ;