Code Reading Flashcards
const fullName: string = ‘Cody Miller’
The string ‘Cody Miller’ is being assigned to the variable fullName of type string
const isCool: boolean = true;
The boolean value true is being assigned to the variable isCool of type boolean
const totalPets: number = 1000;
The number 1000 is being assigned to the variable totalPets of type number
console.log(‘value of fullName:’, fullName);
The log method of the console object is being called with two arguments: The string value of fullName and the value of the variable fullName of type string.
const area: number = width * height;
The result of the expression width times height, both of type number, is being assigned to the variable area of type number.
motto += ‘ is the GOAT’;
The string value of the variable motto is being concatenated with ‘ is the GOAT’, and the result is being reassigned to the variable motto of type string.
const bio: string = My name is ${firstName} ${lastName} and I am ${age} years old.
;
A template literal with the variables firstName, lastName, and age is being interpolated and assigned to the variable bio of type string.
const student: { firstName: string, lastName: string } = {
firstName: ‘Luke’,
lastName: ‘Skywalker’
};
// A TypeScript object is being assigned to the variable student with a firstName property of type string and a lastName property of type string.
// the string Luke is being assigned to the property firstName
const fullName: string = student.firstName + ‘ ‘ + student.lastName;
The firstName property of the student object is being concatenated with a space, and then with the lastName property of the student object. The result is assigned to the variable fullName of type string.
const colors: string[] = [‘red’, ‘white’, ‘blue’];
An array of strings [‘red’, ‘white’, ‘blue’] is being assigned to the variable colors of type array of strings.
console.log(‘value of colors[0]:’, colors[0])
The log method of the console object is being called with two arguments:a string, and colors at 0.
colors[2] = ‘green’;
The string ‘green’ is being assigned to colors at 2
function convertMinutesToSeconds(minutes: number): number {
const seconds: number = minutes * 60;
return seconds;
}
A function named convertMinutesToSeconds is being defined with one parameter minutes of type number. It returns a value of type number.
const convertMinutesToSecondsResult: number = convertMinutesToSeconds(5);
The function convertMinutesToSeconds is being called with the argument 5, and the returned value of that call is being assigned to the variable convertMinutesToSecondsResult of type number.
function getArea(width: number, height: number): number {
const area: number = width * height;
return area;
}
A function named getArea is being defined with two parameters: width and height, both of type number. It returns a value of type number.