Great job on starting your first JavaScript lesson! In the FAQ, test yourself by clicking the correct answer for each question. Then, click Next button at bottom right to continue.
JavaScript Fundamentals
Where to learn JavaScript? Take the JavaScript course free in Software Testing Space.
JavaScript variables allow you to store and manipulate data. They are essential in building applications, providing flexibility for dynamic code. You can declare variables using "var," "let," or "const" keywords. JavaScript variables can hold different data types such as strings, numbers, booleans, arrays, and objects. If you are an absolute beginner, learn about HTML first.
var
is the traditional way of declaring variables. It has function scope or global scope, meaning the variable is accessible within the function or throughout the entire script.let
was introduced in newer versions of JavaScript. It has lexical block scope. It means that the variable is limited to the block where it is declared, such as within an if statement or loop.const
is used for variables that should not be reassigned once they are defined. It also has block scope.
var name = "John"; let age = 25; const PI = 3.14;
JavaScript supports various data types, such as:
- Numbers: e.g., 10, 3.14
- Strings: e.g., "Hello, World!"
- Booleans: e.g., true, false
- Arrays: e.g., [1, 2, 3]
- Objects: e.g., { name: "John", age: 25 }
JavaScript provides operators for performing operations on variables and values. For example:
- Arithmetic operators: e.g., +, -, *, /
- Comparison operators: e.g., ==, ===, <, >, <=, >=
- Logical operators: e.g., &&, ||, !
- String concatenation: e.g., "Hello, " + "World!"
JavaScript example: Variables, Data Types, and Operators
// This is a JavaScript comment. // Create a text file and put the following within <script> and </script> tags.
// Open your HTML file in your browser. Open Developer Tools > Console. // Declare variables var name = "John"; var age = 25; // Concatenate strings var greeting = "Hello, " + name + "!"; // Perform arithmetic operations var result = age * 2 + 10; // Display the results Hello, John! and 60 console.log(greeting); console.log(result);
FAQ (Interview Questions and Answers)
-
Which keyword do you use to declare a variable in JavaScript?
var
let
const
-
What is a data type in JavaScript?
Tuple
Record
Boolean
-
Which operator is used for concatenating strings in JavaScript?
+
-
+ and +=
-
What is the result of the expression 10 % 3 in JavaScript?
3
1
0
-
What is the scope of a variable declared with the "let" keyword?
Block scope
Function scope
Global scope
Your Total Score: 0 out of 5
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.