Skip to lesson content
Web Technologies โ€บ Level 14
LEVEL 14 ยท JAVASCRIPT

JavaScript Fundamentals

Understand values, predict expressions and turn validated input into useful results.

๐Ÿ“ฆ Values + types๐Ÿงฎ Expressions๐Ÿงญ Logic + functions๐Ÿงช Lab + MCQs
01

Learning Objectives

Values

Distinguish a binding from the value it currently holds.

Expressions

Predict an operation from the operand types.

Logic

Choose a branch and stop a bounded loop correctly.

Checks

Test ordinary, zero, blank and invalid input deliberately.

02

HTML, CSS and JavaScript โ€” Three Roles

Workshop page responsibilities
HTML

Heading, labeled inputs, button and result region.

CSS

Readable layout, spacing and visible focus.

JavaScript

Validate values, calculate and report a result.

03

Language and Runtime โ€” Know Where Code Runs

const seats = 30;
const reserved = 12;
console.log(seats - reserved); // 18
04

Load a Script Deliberately

<script src="workshop.js" defer></script>
05

Statements, Expressions and Comments

const seats = 30; // total workshop capacity
let reserved = 12;
reserved = reserved + 3;
const remaining = seats - reserved;
console.log(remaining); // 15
06

let and const โ€” Binding Rules

const workshop = { seats: 30 };
workshop.seats = 32; // allowed property update
// workshop = { seats: 40 }; // TypeError if executed

let reserved = 12;
reserved = 15; // allowed reassignment

Keep reassignment and mutation separate when explaining this example. Object handling will be developed in Level 15.

07

Values Have Types

String

"12" is text; quotes are part of the code notation.

Number

12 and 12.5 are Number values.

Boolean

true and false express a logical result.

Missing values

undefined often represents an absent value; null can represent an intentional empty value.

const label = "Workshop";
const seats = 30;
const full = false;
let note; // undefined
const selectedSession = null;
08

typeof โ€” Useful, with Limits

typeof "12";       // "string"
typeof 12;         // "number"
typeof false;      // "boolean"
typeof undefined;  // "undefined"
typeof null;       // "object"
typeof NaN;        // "number"
09

Arithmetic and Evaluation Order

2 + 3 * 4;     // 14
(2 + 3) * 4;   // 20
17 % 5;        // 2
-17 % 5;       // -2
2 ** 3;        // 8

let reserved = 12;
reserved += 3; // 15
10

Strings, Concatenation and Templates

const seatsText = "30";
const reservedText = "12";
console.log(seatsText + reservedText); // "3012"

const remaining = 18;
const message = `Remaining seats: ${remaining}`;
console.log(message); // Remaining seats: 18
11

Conversion and Validation Are Different

function readSeatCount(text) {
  const trimmed = text.trim();
  if (!/^\d+$/.test(trimmed)) return null;
  const value = Number(trimmed);
  if (!Number.isSafeInteger(value) || value > 1000) return null;
  return value;
}
12

Assignment, Strict Equality and Loose Equality

"12" === 12; // false: different types
"12" == 12;  // true: coercion in this case
12 === 12;   // true
NaN === NaN; // false

let remaining = 18;
remaining = 0; // assignment, not a comparison
13

Truthiness and Logical Operators

Boolean("0"); // true
Boolean(0);   // false

const remaining = 0;
remaining || 10; // 10: zero is falsy
remaining ?? 10; // 0: zero is not null or undefined
14

Control Flow โ€” Conditions and Bounded Loops

const remaining = 3;
if (remaining === 0) {
  console.log("Workshop full");
} else {
  console.log(`${remaining} seats available`);
}

for (let seat = 1; seat <= 3; seat += 1) {
  console.log(`Seat ${seat}`);
} // Seat 1, Seat 2, Seat 3
15

Functions โ€” Inputs, Return Values and Scope

function remainingSeats(capacity, reserved) {
  return capacity - reserved;
}
const result = remainingSeats(30, 12);
console.log(result); // 18
16

Premium Visualizer โ€” From Text to a Result

Follow a fixed workshop example through reading, validation, conversion, calculation and reporting. Use the familiar numbered timeline and playback controls. Explain why each stage is needed instead of jumping directly from a string to an assumed answer.

JAVASCRIPT VALUE TRACE
Step 1 of 5
STEP 01

Begin with text input

The fixed teaching values are the strings "30" and "12".

capacityText = "30"
reservedText = "12"

What is happening?

Input.value provides text. Similar-looking text and numbers can behave differently.

17

Premium Interactive โ€” Values and Seat-Count Lab

Ready to check 30 capacity and 12 reserved.

Operation and inputs

Result and value type

18

Debugging โ€” Find the First Wrong Assumption

Load

Check the external script path and the first console error.

Type

Inspect the value and typeof before an unexpected operation.

Input

Distinguish blank, invalid, converted and accepted input.

Flow

Check the selected branch, loop boundary and returned value.

19

Interview Questions โ€” Flip to Explain

QUESTION

What does dynamically typed mean?

Click or press Enter to explain
ANSWER

Bindings can hold values of different types over time. The values still have types that affect operations.

QUESTION

Does const make an object immutable?

Click or press Enter to explain
ANSWER

No. It prevents reassignment of that binding; allowed properties of the referenced object can still change.

QUESTION

Why can "30" + "12" produce "3012"?

Click or press Enter to explain
ANSWER

The operands are strings, so + concatenates them. Convert deliberately before numeric addition.

QUESTION

Is Number conversion enough to validate a seat count?

Click or press Enter to explain
ANSWER

No. Blank text converts to zero, and other results still need format, integer, range and relationship checks.

QUESTION

How do === and == differ?

Click or press Enter to explain
ANSWER

Strict equality does not coerce different types to match. Loose equality applies coercion rules, which can match a string and number.

QUESTION

Why is "0" truthy while 0 is falsy?

Click or press Enter to explain
ANSWER

The first is a non-empty string; the second is numeric zero. Truthiness depends on the actual value.

QUESTION

What is the difference between returning and logging?

Click or press Enter to explain
ANSWER

Return supplies a result to the function caller and ends the invocation. Logging prints a diagnostic output.

QUESTION

Why can <= and < change a loop result?

Click or press Enter to explain
ANSWER

They include or exclude the boundary value. Trace initialization, condition, update and the intended final iteration.

20

MCQ Practice โ€” Predict Before Running

PRACTICE

1. Which binding should you use when reassignment is intended?

PRACTICE

2. What does const prevent?

PRACTICE

3. What is the result of "3" + "4"?

PRACTICE

4. What does Number("") produce?

PRACTICE

5. What does typeof null produce?

PRACTICE

6. What is the result of "12" === 12?

PRACTICE

7. Which ordinary value is truthy?

PRACTICE

8. What does 0 ?? 10 produce?

PRACTICE

9. What does 2 + 3 * 4 produce?

PRACTICE

10. How many body executions occur for i = 1; i <= 3; i += 1?

PRACTICE

11. What does a function return when it ends without a returned value?

PRACTICE

12. Under this lessonโ€™s seat policy, capacity 30 and reserved 31 should beโ€ฆ

21

Extra Practice โ€” Specific Inputs and Expected Results

Text addition

Use A="3", B="4" in concatenation. Expected: string "34". Switch to numeric addition: number 7.

Blank input

Use A="", B="4" in numeric addition. Expected: 4 after conversion. Seat validation must reject the blank capacity.

Equality

Use A="12", B="12". Expected: strict comparison against Number(B) is false; loose comparison is true.

Zero text

Use A="0" in Boolean(A). Expected: true. Compare Boolean(0) in your own small script: false.

Available seats

Use capacity 30 and reserved 12. Expected: 18 available.

Invalid reservation

Use capacity 30 and reserved 31. Expected: relationship error; do not report a negative availability.

Loop boundary

Print seat numbers 1โ€“3 with <=. Expected: three lines. Switch to <: two lines.

Function return

Write a pure subtraction function with validated numeric arguments 10 and 4. Expected returned Number: 6.

22

Quick Revision

Binding: Use const by default and let for intended reassignment.
Types: A text numeral and a Number are different values.
Inspection: typeof is useful but not complete validation.
Operators: Read operand types and precedence before predicting.
Strings: + may concatenate; templates build clear messages.
Conversion: Convert deliberately and validate the required format.
Comparison: Distinguish assignment, strict equality and coercion.
Truthiness: Zero and missing input are not interchangeable.
Control flow: Trace branches and loop boundaries explicitly.
Functions: Separate inputs, local logic and returned results.
23

Glossary โ€” Flip to Learn

TERM

Binding

Click to see meaning
DEFINITION

Binding

A name associated with a value in an applicable scope.

TERM

Expression

Click to see meaning
DEFINITION

Expression

Code evaluated to produce a value.

TERM

Statement

Click to see meaning
DEFINITION

Statement

A unit of code that performs an action or controls execution.

TERM

Primitive

Click to see meaning
DEFINITION

Primitive

A value in a primitive type category, such as string, number or boolean.

TERM

Coercion

Click to see meaning
DEFINITION

Coercion

An implicit type conversion performed according to an operationโ€™s rules.

TERM

Validation

Click to see meaning
DEFINITION

Validation

Checking whether input meets the taskโ€™s stated acceptance rules.

TERM

Truthy

Click to see meaning
DEFINITION

Truthy

A value that converts to true in a boolean context.

TERM

Scope

Click to see meaning
DEFINITION

Scope

The region of code in which a binding is available under its rules.

TERM

Parameter

Click to see meaning
DEFINITION

Parameter

A named input in a function definition.

TERM

Return value

Click to see meaning
DEFINITION

Return value

The result supplied by a function invocation to its caller.

24

Final Challenge โ€” Explain a Workshop Seat Check

25

Level 14 Complete?

Before marking complete, explain one concatenation surprise, one strict comparison, one zero-versus-blank check, a bounded loop and a returned function value. Completion records a local learning milestone; it is not an assessment score.