What is Statements in javascript?This is 6th Post

Hello friends, in today’s post, we are starting you about JavaScript(what is Javascript where to), what happens. How does the key work, so today you should tell about JavaScript.

What are statements in JavaScript?

What are JavaScript Programs?

A computer program that is given an instruction list to be executed by the computer itself

In all these programming languages, the instruction of programming is called statements in programming languages.

A JavaScript program is a list of programming statements.

If we talk about html, then the program of JavaScript is executed by the web browser itself.

How are statements made in JavaScript?

If we talk about JavaScript, then the statements of JavaScript are formed by values, operators, expressions, keywords, and comments.

In which the statement tells the browser to write “hello world”, for this the operation is performed in JavaScript with the html element key id = “test”

We have explained this through an example below.

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>fullstackgyan</title>
</head>
<body>
<h2>this is the first heading</h2>
<p>this is the first paragraph</p>

<p>A <b>JavaScript program</b> is a list of <b>statements</b> to be executed by a computer.</p>

<p id="test"></p>
<script>
let x, y, z;  // Statement 1
x = 3;        // Statement 2
y = 9;        // Statement 3
z = x + y;    // Statement 4

document.getElementById("test").innerHTML =
"The value of z is " + z + ".";  
</script>
</body>
</html>

Now we have explained to you through another example how hello world is performed on the html element in JavaScript.

An example of this is also being given to you below.

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>fullstackgyan</title>
</head>
<body>

<h2>this is the javascript heading</h2>

<p>In HTML, this statement executed in web browser.</p>

<p id="test"></p>
<script>
document.getElementById("test").innerHTML = "Hello World.";
</script>

</body>
</html>

Most JavaScript programs contain multiple JavaScript statements.

JavaScript statements one by one are executed in the same order as they are written.

If you do not know, then let us tell that JavaScript programs and JavaScript statements are often called JavaScript code.

semicolons ;

Semocolons are separate statements of JavaScript, that is, whenever any statement ends after it; (semicolons) are used

Its example is being given below

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>fullstackgyan</title>
</head>
<body>
<h2>JavaScript Statements</h2>

<p>JavaScript statements are separated by semicolons.</p>
<p id="test1"></p>
<script>
let a, b, c;
a = 5;
b = 6;
c = a + b;
document.getElementById("test1").innerHTML = c;
</script>

</body>
</html>

If we use a line without semicolons then we cannot write multiple statements in one line but if we use semicolons then we can write multiple statements in one line.

Below you are given an example of multiple statements with semicolons

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>fullstackgyan</title>
</head>
<body>

<h2>JavaScript Statements</h2>

<p>we write Multiple statements on one line are allowed.</p>

<p id="test1"></p>

<script>
let a, b, c;
a = 5; b = 6; c = a + b;
document.getElementById("test1").innerHTML = c;
</script>
</body>
</html>

Note:- If you write a statement in one line in JavaScript, then the code will execute even if you give semicolons or not, but giving semicolons is highly recommended.

What is the white space of JavaScript?

JavaScript ignores multiple spaces, so if you can add white space to JavaScript’s script, it is more readable.

To this we are being given both the below statements without space and with space

let yourname = “Ashwani”;
let yourname=”Ashwani”;

Whatever operators ( = + – * / ) we use in the program, then it is considered good practice to keep the space around it so that it looks good in the code.

For example – let x = y + z;

Line length and line breaks in JavaScript

For best readability in JavaScript, programmers often prefer to avoid lines of code longer than 80 characters.

In which if the statement of JavaScript does not fit in one line in JavaScript, then the best way to break it is to break after any operators.

Which we are giving you the script of JavaScript below

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>fullstackgyan</title>
</head>
<body>
<h2>JavaScript Statements</h2>

<p>
The best place to break a code line is after an operator or a comma.
</p>

<p id="test"></p>

<script>
document.getElementById("test").innerHTML =
"Hello World!";
</script>
</script>
</body>
</html>

In this you can see that an operator = has come after innerHTML, in which the line has been broken.

What is JavaScript’s code blocks?

The statement of JavaScript, that is, the code of multiple statements of JavaScript can be defined inside curly brackets.

The purpose of code blocks in JavaScript is to define all the statements to be executed simultaneously.

At one place you will get grouped statements together in the block, for this a function is used in JavaScript, this function of JavaScript is called when someone calls this function.

When called, all the statements in this function are executed simultaneously.

We have shown this to you through the example below.

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>fullstackgyan</title>
</head>
<body>
<h2>JavaScript Statements in this heading2</h2>

<p>JavaScript code blocks are written between { and }</p>

<button type="button" onclick="testFunction()">Click Me</button>

<p id="test1"></p>
<p id="test2"></p>

<script>
function testFunction() {
  document.getElementById("test1").innerHTML = "Hello World!";
  document.getElementById("test2").innerHTML = "How are you Dear?";
}
</script>
</body>
</html>

In this you can see that two statements have been given in this testFunction, in which both the statements have been taken as id test1 in the first statement and test2 in the second, in which if someone clicks on the button, then the html element in it on the basis of id. value will be bind

keywords in javascript

JavaScript statements often begin with a keyword to identify the JavaScript identity used.

Our reserved word reference lists all JavaScript keywords.

Below are some such keywords that you should be aware of.

KeywordDescription
varDeclares a block variables
letDeclares a block variable
constDeclares a block constant
ifMarks a block of statements to be executed on a condition
switchMarks a block of statements to be executed in different cases
forMark a block of statements to be executed in a loop
functionDeclares a function
returnExits a function
tryImplements error handling to a block of statements

In JavaScript, all these keywords are reserved words, because they are all reserved words, they cannot name the variables of all the keywords.

Request – If you found this post useful for you(what is javascript syntax), then do not limit it to yourself(basic infomation of javascript), do share it

Leave a Comment