What is JavaScript Statement?

← PrevNext →

A Statement in JavaScript is a Group of Commands, put together inside curly braces { }, called JavaScript Code Block. A Statement usually ends with a ; (semi colon). A web browser executes these commands to perform a task.

Syntax

{
    A Statement;
}

JavaScript Statement Example

Here in this example, I have written few statements that tells the browser to write a word in its original form and later using a while statement, reverse the word.

<html>
<body>
    <input type='text' id='tb' value='COMPUTER SCIENCE' />
    <input type='button' value='Click it' onclick='reverse_text()'>
    
    <p id='result'></p>
</body>
<script>
    let reverse_text = () => {
        let sWord = document.getElementById('tb').value;
        let res = document.getElementById('result');

        res.innerHTML = 'You have entered: ' + sWord;
        res.innerHTML = res.innerHTML + '<br /><br />';

        let i = sWord.length;

        res.innerHTML = res.innerHTML + ' ' +
      	'<b> is now Reveresed </b> <br /><br />';

        while (i--) {
            res.innerHTML = res.innerHTML + ' ' + sWord[i];
        }
    }
</script>
</html>
Try it

The result,



← PreviousNext →