Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Zhang authored and Oliver Zhang committed Sep 18, 2024
1 parent ccd26eb commit f67dc89
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 80 deletions.
36 changes: 0 additions & 36 deletions content/english/javascript-basics/javascript_whileloops.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
# **Variables and Data Types**
---
title: "Variables and Data Type"
date: 2020-07-28T11:45:38-07:00
draft: true
hidden: true
weight: 4
---

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

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

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

3. Using "const" (which is short for constant) like this:
```
3. Using `const` (which is short for constant) like this:
```javascript
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_.
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:
JavaScript has 8 different data types:
- String
- Number
- Boolean
Expand All @@ -35,53 +41,52 @@ JavaScript has 8 different Data Types:
- 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";
```
Strings can be made up of words or a group of letters.

```javascript
// 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;
```
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).

```javascript
// 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;
```
Booleans represent true and false values so like telling the truth and telling a lie.

```javascript
// 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;
```
Undefined means that the variable has no value (because 0 is technically a value)!

```javascript
// 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.

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

```
// Array object:
const cars = ["Saab", "Volvo", "BMW"];

Expand All @@ -93,11 +98,11 @@ 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
Use the `typeof` operator! If you run the `typeof` operator with a variable, it'll tell you what it is:

```
```javascript
typeof "Amy" // returns "string"
typeof 0 // returns "number"
typeof (3) // returns "number" (the parantheses don't do anything)
typeof (3 + 4) // returns "number"
```
42 changes: 42 additions & 0 deletions content/english/javascript-basics/while-loops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: "While Loops"
date: 2020-07-28T11:45:38-07:00
draft: true
hidden: true
weight: 3
---

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 parentheses `()`, and then put the action (or actions) to be performed inside of curly brackets `{}`. Here is the set up:

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

Now let's jump into some examples!

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

```javascript
// 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).

```javascript
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 f67dc89

Please sign in to comment.