Student Lab Workbook: A Journey into JavaScript Objects
Introduction
Welcome to this journey into JavaScript and its Object-Oriented features.
This workbook will guide you through the fundamentals of JavaScript, leading up to an enlightening exploration into Objects.
An OBJECT is : Data Fields PLUS METHODS
An OBJECT is box. This box is an object is an in-memory data structure which does tight binding of data and methods]. This tight binding give rise to the ‘this’ keyword.
We will investigate the nature of JavaScript Objects as we learn about the Debugger in JavaScript.
This lab worksheet provides hands-on exercises and examples to solidify your understanding and skills.
Section 1: JavaScript Fundamentals
Exercise 1: Hello, World!
Let's start by writing a simple JavaScript program.
Open your text editor and create a new file named hello.js. Write the following code in the file: console.log('Hello, World!');
Save the file and run it using Node.js by typing node hello.js in your terminal. Confirm that it prints Hello, World! to the console. Exercise 2: Variables and Constants
Understand the use of variables and constants.
Declare a variable name and assign your name to it. Declare a constant birthYear and assign your birth year to it.
let name = 'Your Name';
const birthYear = 1990;
console.log(name, birthYear);
Section 2: Control Flow
Exercise 3: Conditional Statements
Practice using if, else if, and else statements.
Write a program that checks if a number is positive, negative, or zero.
let number = prompt("Enter a number: ");
if (number > 0) {
console.log("The number is positive.");
} else if (number < 0) {
console.log("The number is negative.");
} else {
console.log("The number is zero.");
}
Exercise 4: Loops
Get comfortable with loops by writing a program that counts from 1 to 10.
// Let's make a 10x10 multiplication table
for (let i = 1; i <= 10; i++) {
for (let j = 1; j<= 10; j++){
console.log( i + " * " + j + " is " + i*j )
}
}
Section 3: Functions
Reference this worksheet for more fun with Functions: