Search Header Logo
Undefined, null, NaN

Undefined, null, NaN

Assessment

Presentation

Other

KG - University

Practice Problem

Easy

Created by

Eric Foster

Used 1+ times

FREE Resource

3 Slides • 3 Questions

1

Open Ended

Write code that results in "undefined" in the console. Include a console.log()

2

// Variable declared but not assigned

let username;

console.log(username); // Output: undefined

// Missing function parameter

function greet(name) {

  console.log(name);

}

greet();// Output: undefined

Undefined

3

Open Ended

Write code that results in "NaN" in the console. Include a console.log()

4

// Programmer sets value to null on purpose

let profilePicture = null; // User hasn't uploaded a picture yet

console.log(profilePicture); // Output: null

// Resetting a value

let score = 100;

score = null; // Intentionally clearing the score

console.log(score);// Output: null

null

5

Open Ended

Write code that uses "null." Include a console.log()

6

// Trying to convert text to a number

let age = Number("twenty"); 

console.log(age); // Output: NaN

// Math with values that aren't numbers

let result = "hello" * 5;

console.log(result); // Output: NaN

// Parsing fails

let value = parseInt("abc");

console.log(value);// Output: NaN

NaN

Write code that results in "undefined" in the console. Include a console.log()

Show answer

Auto Play

Slide 1 / 6

OPEN ENDED