Hexadecimal in javascript

Something Like that:
0xFF

JavaScript interprets numeric constants as hexadecimal if they are preceded by 0x.
For example I want to write number like 255
0xFF

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var x = 0xFF; 
document.getElementById("demo").innerHTML = x;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”prjpew” default_tab=”js,result” user=”pradeepanvi”]See the Pen Hexadecimal in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

255

Precision in Javascript

Something Like that:
0.2 + 0.1

The maximum number of decimals is 17, but floating point arithmetic is not always 100% accurate
For example I want to write number like 0.30000000000000004
0.2 + 0.1

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var x = 0.2 + 0.1;
document.getElementById("demo").innerHTML = x;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”Vzvywq” default_tab=”result” user=”pradeepanvi”]See the Pen Precision in Javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

0.30000000000000004

But one thing if we plus 0.2 + 0.1 it should be write 0.3

To solve the problem above, it helps to multiply and divide

After that add this JS code.

JS

var x = (0.2 * 10 + 0.1 * 10) / 10;
document.getElementById("demo").innerHTML = x;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”RZWxRz” default_tab=”result” user=”pradeepanvi”]See the Pen Precision in Javascript 02 by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

0.3

Number in javascript

Something Like that:
e

Extra large or extra small numbers can be written with scientific (exponent) notation
For example I want to write number like 12300000
123e5

For that you need to create first html code.

HTML

x value <span id="demo"></span><br>
y value <span id="demo2"></span>

After that add this JS code.

JS

var x = 123e5;
var y = 123e-5;
document.getElementById("demo").innerHTML = x;
document.getElementById("demo2").innerHTML = y;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”XamzGa” default_tab=”result” user=”pradeepanvi”]See the Pen Number in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

x value 12300000
y value 0.00123

Split Text in javascript

Something Like that:
split()

For example I have a word “Home2it”. I want to should be split like H,o,m,e,2,i,t
Home2it

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var str = "Home2it";
var arr = str.split("");
var res = "";
var i;
for (i = 0; i < arr.length; i++) {
    res += arr[i] + ","
}
document.getElementById("demo").innerHTML = res;

[codepen_embed height="265" theme_id="0" slug_hash="ayvLXd" default_tab="result" user="pradeepanvi"]See the Pen Split Text in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now If you want to change "," into "|"

JS

var str = "Home2it";
var arr = str.split("");
var res = "";
var i;
for (i = 0; i < arr.length; i++) {
    res += arr[i] + "|"
}
document.getElementById("demo").innerHTML = res;

Or text Like this
H
o
m
e
2
i
t

JS

var str = "Home2it";
var arr = str.split("");
var res = "";
var i;
for (i = 0; i < arr.length; i++) {
    res += arr[i] + "
" } document.getElementById("demo").innerHTML = res;

Extracting String Characters in javascript

Something Like that:
charAt() charCodeAt()

Extracting String Characters
There are 2 safe methods for extracting string characters:
charAt(position)
charCodeAt(position)

charAt()

The charAt() method returns the character at a specified index (position) in a string:

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var str = "HELLO Home2it";
res = str.charAt(0);
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”gxpddL” default_tab=”result” user=”pradeepanvi”]See the Pen charAt in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

charCodeAt()

The charCodeAt() method returns the unicode of the character at a specified index in a string

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var str = "HELLO Home2it";
res = str.charCodeAt(0);
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”jLPvQZ” default_tab=”result” user=”pradeepanvi”]See the Pen charCodeAt in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see 72.

What is 72
This is character code on keyboard use alt+72 and then you can see H

Join two or more words in javascript

Something Like that:
concat()

The concat() Method
concat() joins two or more strings

For example I want to written HELLO HOME2IT.

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var text1 = "Hello";
var text2 = "Home2it";
res = text1.concat(" ", text2);
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”jLPvGG” default_tab=”result” user=”pradeepanvi”]See the Pen Join two or more words in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see.
Hello Home2it

Second option is that

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var res = "Hello".concat(" ", "Home2it");
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”MvwqVG” default_tab=”result” user=”pradeepanvi”]See the Pen Join two or more words in javascript 02 by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Upper Case and Lower Case in Javascript

Something Like that:
toUpperCase() toLowerCase()

Converting to Upper and Lower Case
A string is converted to upper case with toUpperCase()

For example I want to written HELLO HOME2IT.

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var text1 = "Hello home2it";
var res = text1.toUpperCase();
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”prJOzP” default_tab=”result” user=”pradeepanvi”]See the Pen Upper Case in Javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see.
HELLO HOME2IT

Now I want HELLO HOME2IT should be lower case hello home2it.

A string is converted to lower case with toLowerCase()

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var text1 = "Hello home2it";
var res = text1.toLowerCase();
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”WEvgvo” default_tab=”result” user=”pradeepanvi”]See the Pen Lower Case in Javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Replace and Global Replace in javascript

Something Like that:
replace()

Replacing String Content
The replace() method replaces a specified value with another value in a string

For example I want to written Please visit Home2it! The new Microsoft.

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

str = "Please visit Microsoft! The new Microsoft";
var res = str.replace("Microsoft", "Home2it");
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”PKqBmL” default_tab=”js,result” user=”pradeepanvi”]See the Pen Replace in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see.
Please visit Home2it! The new Microsoft

But there is one thing, We want to change all Microsoft text to Home2it.

For that we need to use global replace /Microsoft/g

The replace() method can also take a regular expression as the search value.
By default, the replace() function replaces only the first match. To replace all matches, use a regular expression with a g flag (for global match)

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

str = "Please visit Microsoft! The new Microsoft";
var res = str.replace(/Microsoft/g, "Home2it");
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”gxpjvy” default_tab=”result” user=”pradeepanvi”]See the Pen Global Replace in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Substr in javascript

Something Like that:
substr

substr() is similar to slice().
The difference is that the second parameter specifies the length of the extracted part.

For example I want to written Banana.

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var str = "Apple, Banana, Kiwi";
var res = str.substr(7, 6);
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”ZJGjBO” default_tab=”js,result” user=”pradeepanvi”]See the Pen Substr in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see Banana

Substring in javascript

Something Like that:
substring

substring() is similar to slice().
The difference is that substring() cannot accept negative indexes.

For example I want to written Banana.

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var str = "Apple, Banana, Kiwi";
var res = str.substring(7, 13);
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”mMyZYd” default_tab=”result” user=”pradeepanvi”]See the Pen substring in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see Banana