Automatic Semicolon Insertion in javascript

Something Like that:
Automatic Semicolon Insertion

What is Automatic Semicolon Insertion?
If we write some code and just gave enter, so It will be add automatic semicolon.

For that you need to create first html code.

HTML

<p id="demo1"></p>

After that add this JS code.

JS

function getPerson(){
    return
    {
        firstname: 'Tony'
    }
}

document.getElementById("demo1").innerHTML = getPerson();

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

This will be written undefined. because after return javascript insert semicolon due to enter
Now you can see

undefined

Now next example without enter

For that you need to create first html code.

HTML

<p id="demo1"></p>

After that add this JS code.

JS

function getPerson(){
    return
    {
        firstname: 'Tony'
    }
}

document.getElementById("demo1").innerHTML = getPerson();

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”EvXjwa” default_tab=”js” user=”pradeepanvi”]See the Pen Automatic Semicolon Insertion in javascript 02 by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

This will be show Object as written.
Now you can see

[object Object]

Leave a Reply

Your email address will not be published. Required fields are marked *