# Javascript Basics

{% embed url="<https://www.youtube.com/watch?v=cmIvp0pD2io&list=PLT5Jhb7lgSBNl46W_y6sOb_W54C9_L6Ml&index=22>" %}

1\. Variables and Data Types

In JavaScript, you can use the `var`, `let`, or `const` keywords to declare variables. Here are some basic data types:

```javascript
// Variables
var myVariable = "Hello, World!";
let anotherVariable = 42;
const pi = 3.14;

// Data Types
let str = "String";
let num = 42;
let bool = true;
let arr = [1, 2, 3];
let obj = { key: "value" };
```

#### 2. Operators

JavaScript supports various operators for arithmetic, comparison, and logical operations:

```javascript
let a = 5;
let b = 10;

// Arithmetic operators
let sum = a + b;
let difference = a - b;
let product = a * b;
let quotient = a / b;

// Comparison operators
let isEqual = a === b;
let isNotEqual = a !== b;
let greaterThan = a > b;
let lessThan = a < b;

// Logical operators
let andOperator = true && false;
let orOperator = true || false;
let notOperator = !true;
```

#### 3. Control Flow

Use `if`, `else if`, and `else` statements for control flow:

```javascript
let x = 10;

if (x > 0) {
    console.log("Positive");
} else if (x < 0) {
    console.log("Negative");
} else {
    console.log("Zero");
}
```

#### 4. Loops

JavaScript supports `for` and `while` loops:

```javascript
// For loop
for (let i = 0; i < 5; i++) {
    console.log(i);
}

// While loop
let j = 0;
while (j < 5) {
    console.log(j);
    j++;
}
```

#### 5. Functions

Define functions using the `function` keyword:

```javascript
function greet(name) {
    console.log("Hello, " + name + "!");
}

greet("John");
```

#### 6. Arrays and Objects

Arrays and objects are crucial data structures in JavaScript:

```javascript
// Arrays
let fruits = ["apple", "banana", "orange"];

// Objects
let person = {
    name: "John",
    age: 25,
    isStudent: false
};
```

This is just a brief overview. If you have specific questions or topics you'd like to dive deeper into, feel free to ask!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tkssharma-devops.gitbook.io/web-developer-bootcamp/javascript-learning-basics/javascript-basics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
