AltSchool Of Engineering Tinyuka’24 Month 4 Week 4
This week began with an engaging revision session as usual (check out the summary here definitely worth a read if you missed it!). Afterward, we kicked off with JavaScript, skillfully guided by our excellent instructor. Getting Started with JavaScript JavaScript is a versatile programming language primarily used for web development. It allows for interactive features on websites, making it essential for modern web applications. Key Fundamentals 1. Variables: Variables are containers for storing data, declared using var, let, or const. Naming Conventions: Must start with a non-digit character. Use Camel Case for multi-word names (e.g., myVariableName). Avoid reserved keywords and abbreviations; names should be descriptive. Example: let userAge = 30; 2. Data Types: Understand the various data types in JavaScript, such as strings, numbers, booleans, objects, and arrays. 3. User Interaction: Use methods like alert, prompt, and confirm for user interaction, along with console.log for debugging. 4. Type Conversions: Be aware of how JavaScript handles type conversions, especially between strings and numbers. 5. Operators: Familiarize yourself with different types of operators: Math Operators: +, -, *, / Comparison Operators: ==, ===, !=, !== Logical Operators: &&, ||, ! Bitwise Operators: &, |, ^ Null Coalescing: ?? Optional Chaining: ?. 6. Conditional Branching: Use if statements, the ternary operator ?, and switch statements to control the flow of your code based on conditions. 7. Loops: Implement loops such as while, for, for…in, and for…of to iterate over data structures. 8. Functions: Learn about different ways to define functions: Declaration: function myFunction() { } Arrow Functions: const myFunction = () => { } Function Expressions: const myFunction = function() { } 9. Variable Scope: const; variables declared with const are immutable and cannot be reassigned. let and var: Both can be reassigned, but let has block scope, while var has function scope. Data Types in JavaScript In JavaScript, every value has a specific type, which dictates how that value can be used. Here’s an overview of the primary data types: 1. Numbers: JavaScript can represent both integers and floating-point numbers. For example, 42 (integer) and 3.14 (floating-point). 2. Strings: Strings must be enclosed in quotes, which can be single ('), double ("), or backticks (). For instance,let greeting = "Hello, World!";`. 3. Booleans: This type has only two possible values: true and false. They are commonly used in conditional statements. 4. Undefined: A variable that hasn't been assigned a value or hasn't been declared will hold the type undefined. For example, let x; // x is undefined. 5. BigInt: BigInt is used for integers larger than the safe integer limit for regular numbers. You can create a BigInt by appending n to the end of the number, like const bigNumber = 123456789012345678901234567890n;. 6. Objects: Objects are collections of data and can be used to store various keyed values. For example, const person = { name: "Alice", age: 30 }; creates an object named person. 7. Null: The null type represents an intentional absence of any value. It signifies "nothing," "empty," or "value unknown." For instance, let user = null;. 8. Type Checking: To determine the type of a value, you can use the typeof operator. For example, typeof "Hello" returns "string". Note: Interestingly, typeof null returns "object" due to a historical quirk in JavaScript. User Interaction in JavaScript JavaScript provides several methods for interacting with users through modal dialogs: 1. alert() Method: This method displays a simple alert box containing a message and an "OK" button. It is primarily used to convey information to the user. Example: alert("Welcome to our website!"); 2. prompt() Method: The prompt() method presents a modal window with a message, an input field for user input, and "OK" and "Cancel" buttons. It allows you to collect user responses. It can take two arguments: a message to display and a default value for the input field. Example: let name = prompt("What is your name?", "John Doe"); 3. confirm() Method: This method displays a modal window with a question and two buttons: "OK" and "Cancel." It is useful for asking users to confirm an action. Example: let isConfirmed = confirm("Do you want to proceed?"); User Interaction Methods in JavaScript: Overview JavaScript offers several methods to interact with users through modal dialog boxes: 1. alert() Method: The alert() method creates an alert box that displays a message along with an "OK" button. This is typically used to provide important information to users. Example: alert("This is an important announcement!"); 2. prompt() Method: The prompt() method opens a modal dialog that presents a message, an input field for user input, and "OK" and "Cancel" buttons. It can accept two arguments: the m

This week began with an engaging revision session as usual (check out the summary here definitely worth a read if you missed it!). Afterward, we kicked off with JavaScript, skillfully guided by our excellent instructor.
Getting Started with JavaScript
JavaScript is a versatile programming language primarily used for web development. It allows for interactive features on websites, making it essential for modern web applications.
Key Fundamentals
1. Variables: Variables are containers for storing data, declared using var, let, or const.
Naming Conventions:
Must start with a non-digit character.
Use Camel Case for multi-word names (e.g., myVariableName).
Avoid reserved keywords and abbreviations; names should be descriptive.
Example:
let userAge = 30;
2. Data Types: Understand the various data types in JavaScript, such as strings, numbers, booleans, objects, and arrays.
3. User Interaction: Use methods like alert, prompt, and confirm for user interaction, along with console.log for debugging.
4. Type Conversions: Be aware of how JavaScript handles type conversions, especially between strings and numbers.
5. Operators: Familiarize yourself with different types of operators:
Math Operators: +, -, *, /
Comparison Operators: ==, ===, !=, !==
Logical Operators: &&, ||, !
Bitwise Operators: &, |, ^
Null Coalescing: ??
Optional Chaining: ?.
6. Conditional Branching: Use if statements, the ternary operator ?, and switch statements to control the flow of your code based on conditions.
7. Loops: Implement loops such as while, for
, for…in
, and for…of
to iterate over data structures.
8. Functions: Learn about different ways to define functions:
Declaration:
function myFunction() { }
Arrow Functions:
const myFunction = () => { }
Function Expressions:
const myFunction = function() { }
9. Variable Scope: const;
variables declared with const are immutable and cannot be reassigned.
- let and var: Both can be reassigned, but let has block scope, while var has function scope.
Data Types in JavaScript
In JavaScript, every value has a specific type, which dictates how that value can be used. Here’s an overview of the primary data types:
1. Numbers: JavaScript can represent both integers and floating-point numbers. For example, 42
(integer) and 3.14
(floating-point).
2. Strings: Strings must be enclosed in quotes, which can be single (')
, double (")
, or backticks (
). For instance,
let greeting = "Hello, World!";`.
3. Booleans: This type has only two possible values: true
and false
. They are commonly used in conditional statements.
4. Undefined: A variable that hasn't been assigned a value or hasn't been declared will hold the type undefined. For example, let x; // x is undefined.
5. BigInt: BigInt is used for integers larger than the safe integer limit for regular numbers. You can create a BigInt by appending n to the end of the number, like const bigNumber = 123456789012345678901234567890n;
.
6. Objects: Objects are collections of data and can be used to store various keyed values. For example, const person = { name: "Alice", age: 30 };
creates an object named person.
7. Null: The null type represents an intentional absence of any value. It signifies "nothing," "empty," or "value unknown." For instance, let user = null;
.
8. Type Checking: To determine the type of a value, you can use the typeof
operator. For example, typeof
"Hello"
returns "string"
.
Note: Interestingly, typeof
null returns "object"
due to a historical quirk in JavaScript.
User Interaction in JavaScript
JavaScript provides several methods for interacting with users through modal dialogs:
1. alert() Method: This method displays a simple alert box containing a message and an "OK" button. It is primarily used to convey information to the user.
Example: alert("Welcome to our website!");
2. prompt() Method: The prompt()
method presents a modal window with a message, an input field for user input, and "OK" and "Cancel" buttons. It allows you to collect user responses. It can take two arguments: a message to display and a default value for the input field.
Example: let name = prompt("What is your name?", "John Doe");
3. confirm() Method: This method displays a modal window with a question and two buttons: "OK" and "Cancel." It is useful for asking users to confirm an action.
Example: let isConfirmed = confirm("Do you want to proceed?");
User Interaction Methods in JavaScript: Overview
JavaScript offers several methods to interact with users through modal dialog boxes:
1. alert() Method: The alert()
method creates an alert box that displays a message along with an "OK" button. This is typically used to provide important information to users.
Example: alert("This is an important announcement!");
2. prompt() Method: The prompt()
method opens a modal dialog that presents a message, an input field for user input, and "OK" and "Cancel" buttons. It can accept two arguments: the message to display and an optional default input value.
Example: let userResponse = prompt("Please enter your name:", "Anonymous");
3. confirm() Method: The confirm()
method shows a modal dialog with a question and two buttons: "OK" and "Cancel." This is useful for confirming user actions.
Example: let userConfirmed = confirm("Are you sure you want to delete this item?");
Type Conversion in JavaScript
Type conversion refers to the process of changing a value from one data type to another in JavaScript. Here are the main types of conversions:
1. String Conversion: You can convert values to strings using the String function or the .toString()
method.
Example:
let num = 123;
let strNum = String(num); // "123"
// or
let anotherStrNum = num.toString(); // "123"
2. Numeric Conversion: To convert values to numbers, you can use the Number function, parseInt, parseFloat, or the unary plus (+) operator.
Example:
let str = "456";
let num = Number(str); // 456
let intNum = parseInt(str); // 456
let floatNum = parseFloat("3.14"); // 3.14
let unaryNum = +"789"; // 789
3. Boolean Conversion: You can convert values to booleans using the Boolean constructor or the double negation (!!).
Example:
let truthyValue = "Hello";
let boolValue = Boolean(truthyValue); // true
let anotherBoolValue = !!truthyValue; // true
Operators in JavaScript
JavaScript supports various types of operators that allow you to perform different operations on values. Here’s an overview of some key operator categories:
1. Mathematical Operators: These operators perform arithmetic calculations:
Addition (+): Adds two numbers.
Example: let sum = 5 + 3; // 8
Subtraction (-): Subtracts one number from another.
Example: let difference = 5 - 3; // 2
Multiplication (*): Multiplies two numbers.
Example: let product = 5 * 3; // 15
Division (/): Divides one number by another.
Example: let quotient = 10 / 2; // 5
Remainder (%): Returns the remainder of a division operation.
Example: let remainder = 5 % 2; // 1
Exponentiation ():** Raises a number to the power of another.
Example: let power = 2 ** 3; // 8
2. Comparison Operators: Used to compare values and return a Boolean result (true or false).
3. Logical Operators: Used to combine or invert Boolean values.
4. Bitwise Operators: Operate on binary representations of numbers.
5. Null Coalescing: Returns the right-hand operand when the left-hand operand is null or undefined.
6. Optional Chaining: Allows safe access to deeply nested object properties without throwing errors if a property does not exist.
Comparison Operators in JavaScript
In JavaScript, comparison operators are used to compare values, returning a Boolean result (true or false). Here’s a summary of the key comparison operators:
1. Equals to (==): Checks if two values are equal, ignoring their data types.
Example:
console.log(5 == '5'); // true
2. Strictly Equal to (===): Checks if two values are equal and of the same type.
Example:
console.log(5 === '5'); // false
3. Not Equal to (!=): Checks if two values are not equal, again ignoring their types.
Example:
console.log(5 != '5'); // false
4.Greater Than (>): Determines if the left value is greater than the right value.
Example:
console.log(10 > 5); // true
5. Less Than (<): Checks if the left value is less than the right value.
Example:
console.log(3 < 7); // true
6. Greater Than or Equal To (>=): Checks if the left value is greater than or equal to the right value.
Example:
console.log(5 >= 5); // true
7. Less Than or Equal To (<=): Checks if the left value is less than or equal to the right value.
Example:
console.log(4 <= 6); // true
Logical Operators in JavaScript
Logical operators in JavaScript are used to combine or manipulate Boolean values. Here’s an overview of the primary logical operators:
1. Logical OR (||): This operator evaluates its operands from left to right and returns the first truthy operand. If all operands are falsy, it returns the last operand.
Example:
let a = 0;
let b = "Hello";
let result = a || b; // "Hello"
2. Logical AND (&&): The AND operator returns true only if both operands are truthy. If either operand is falsy, the entire expression evaluates to false.
Example:
let x = true;
let y = false;
let result = x && y; // false
3. Logical NOT (!): The NOT operator inverts the truth value of an expression. It returns false if the expression is truthy and true if it is falsy.
Example:
let isActive = true;
let result = !isActive; // false
Thank you for being an incredible part of this learning journey! Your support and engagement truly means the world to me. I encourage you to dive deeper into the concepts we've explored and keep practicing to refine your skills.
I’d love to hear your thoughts and insights, please share your feedback in the comments below to join the conversation!
I’m Ikoh Sylva, a passionate cloud computing enthusiast with hands-on experience in AWS. I'm documenting my cloud journey from a beginner’s perspective, and I hope to inspire others along the way. If you find my content valuable, please like and follow my posts, and consider sharing this article with anyone embarking on their own cloud journey.
Let’s connect on social media, I’d love to engage with you further!