Table of Contents
What is a Java Script
- In JavaScript, statements are the individual units of code that the interpreter can execute. They can be simple or complex and are typically separated by semicolons. Here’s a basic example:
let x = 5;
let y = 10;
let result = x + y;
console.log(result);
In this example, each line represents a statement.
- let x = 5;: This statement declares a variable x and assigns it the value 5.
- let y = 10;: This statement declares a variable y and assigns it the value 10.
- let result = x + y;: This statement declares a variable result and assigns it the sum of x and y.
- console.log(result);: This statement outputs the value of result to the console.
JavaScript statements can also include conditional statements, loops, and function calls, among other things. They are the building blocks that make up JavaScript programs!
In JavaScript, statements are the individual units of code that the interpreter executes. They can be simple or compound, and they control the flow of a program. Let me give you a couple of examples:
1. Variable Declaration
javascript
let x; // Declaring a variable named 'x'
2. Assignment Statement
javascript
x = 10; // Assigning the value 10 to the variable 'x'
3. Conditional Statement (if)
javascript
if (x > 5) {
console.log('x is greater than 5');
} else {
console.log('x is not greater than 5');
}
4. Loop Statement (for)
javascript
for (let i = 0; i < 5; i++) {
console.log(i); // Prints numbers 0 to 4
}
5. Function Declaration
javascript
function greet(name) {
console.log('Hello, ' + name + '!');
}
greet('John'); // Calls the function with the argument 'John'
- JavaScript keywords are reserved words that have a special meaning in the language. They cannot be used as identifiers (such as variable names or function names) because they are already used by the language itself. Here is a list of JavaScript keywords:
List of JavaScript keywords
break | case | class | const | continue | debugger |
default | delete | do | else | export | extends |
false | finally | for | function | if | import |
instanceof | new | null | return | super | switch |
this | throw | true | try | typeof | var |
void | while | with | catch | in |