June 21, 2023

JavaScript Fundamentals

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.

  1. 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.
  2. 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.
  3. 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:

  1. Numbers: e.g., 10, 3.14
  2. Strings: e.g., "Hello, World!"
  3. Booleans: e.g., true, false
  4. Arrays: e.g., [1, 2, 3]
  5. Objects: e.g., { name: "John", age: 25 }

JavaScript provides operators for performing operations on variables and values. For example:

  1. Arithmetic operators: e.g., +, -, *, /
  2. Comparison operators: e.g., ==, ===, <, >, <=, >=
  3. Logical operators: e.g., &&, ||, !
  4. 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)

  1. Which keyword do you use to declare a variable in JavaScript?
    var
    let
    const
  2. What is a data type in JavaScript?
    Tuple
    Record
    Boolean
  3. Which operator is used for concatenating strings in JavaScript?
    +
    -
    + and +=
  4. What is the result of the expression 10 % 3 in JavaScript?
    3
    1
    0
  5. 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

Remember to just comment if you have any doubts or queries.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.