Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
smithkaylee authored Sep 18, 2024
1 parent 9820e21 commit ccd26eb
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
103 changes: 103 additions & 0 deletions content/english/javascript-basics/javascript_varsanddatatypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# **Variables and Data Types**

To make a variable in JavaScript, you have 3 options.

1. Using "var" (which is short for variable) like this:
```
var x = 5;
var y = 6;
var z = x + y;
```

2. Using "let" like this:
```
let x = 5;
let y = 6;
let z = x + y;
```

3. Using "const" (which is short for constant) like this:
```
const x = 5;
const y = 6;
```
It's important to realize here that a constant does not change. This means that these values are stuck to what they are set to at the beginning.

You can use "var", "let", and "const" to hold any of the different data types in JavaScript. This is called having _dynamic types_.

JavaScript has 8 different Data Types:
- String
- Number
- Boolean
- Undefined
- Null
- Symbol
- Object
- BigInt


We're going to go over the most important ones: String, Number, Boolean, Undefined, and Object!

## String
Strings can be made up of words or a group of letters.

```
// String examples
let animal = "Elephant";
let alphabet = "abc";
let name = "John";
```

## Number
Numbers can be used for all different types of numbers (small and big!). That is, until you need REALLLLY big numbers, then you need a special variable called a bigint (but that's a topic for another time).

```
// Number examples
let age = 16;
let weight = 7.5;
```

## Boolean
Booleans represent true and false values so like telling the truth and telling a lie.

```
// Boolean examples
let truth = true;
let lie = false;
let x = true;
let y = false;
```

## Undefined
Undefined means that the variable has no value (because 0 is technically a value)!

```
// Undefined example
let x = undefined;
```

## Object
An object in JavaScript is a bit more complicated. It can be a built-in object such as an array, dates, maps, sets, and more, or it can be a user-defined array, which means it can be any group of data.

const person = {firstName:"John", lastName:"Doe"};

```
// Array object:
const cars = ["Saab", "Volvo", "BMW"];
// Date object:
const date = new Date("2022-03-25");
// User-defined object (in this case first and last names)
const person = {firstName:"John", lastName:"Doe"};
```

## When you're unsure what type of variable it is...
Use the typeof operator! If you run the typeof operator with a variable, it'll tell you what it is

```
typeof "Amy" // returns "string"
typeof 0 // returns "number"
typeof (3) // returns "number" (the parantheses don't do anything)
typeof (3 + 4) // returns "number"
36 changes: 36 additions & 0 deletions content/english/javascript-basics/javascript_whileloops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# **While Loops**

A while loop is just that, it's a section of code that continues to carry out a few actions "while" the condition is true. We start with the word "while" followed by the condition that's true in parantheses (), and then put the action (or actions) to be performed inside of curly brackets {}. Here is the set up:

```
// While loop setup
while (condition is true) {
// action to perform
}
```

Now lets jump into some examples!

## Examples
Say we want to create a loop that runs 8 times.

```
// 8x example
let i = 0; // set a counter variable
while( i < 8) {
i++; //moves to the next iteration of the loop (makes the loop run through this part again)
}
```

The condition could also be a statement, such as a boolean (true/false). For example, say we wanted to read through different comments on a video until we read all of them. To do this in a while loop we would need a few different variables (you can ignore the fancy node words).

```
const commentIterator = video.createNodeIterator(video, NodeFilter.SHOW_COMMENT) // this is a way to move from one comment to the next on the video
let currentComment; // this is a placeholder for the current comment
// this while loop will keep looping while there is a "nextNode" which is another way of saying there is another comment after this
while (currentComment = commentIterator.nextNode()) {
console.log(currentComment.textContent.trim()); //this prints out the current comment so we can read it!
}
```

0 comments on commit ccd26eb

Please sign in to comment.