Skip to content

[p5.js 2.0 Bug Report]: noise(null) is treated as noise(0) while noise(undefined) errors, and this behaviour is undocumented and inconsistent. #8407

@shuklaaryan367-byte

Description

@shuklaaryan367-byte

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.1.2

Web browser and version

Google Chrome Version 143.0.7499.170

Operating system

Windows 11

Steps to reproduce this

Steps:

  1. Run the sketch below
  2. Compare the outputs of noise(null) and noise(0)
  3. Observe that they are identical, while noise(undefined) throws an FES warning

Snippet:

function setup() {
  noCanvas();

  console.log("null:", noise(null));
  console.log("0:", noise(0));
  console.log("undefined:", noise(undefined));
}

Explanation:

noise(null) returns the same value as noise(0), while noise(undefined) produces a NaN and a Friendly Error message. Both null and undefined represent missing values in JavaScript, but they are handled differently here. This behaviour is not documented and can lead to silent bugs when null is passed unintentionally.

I'm happy to take on this task, if this is approved

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions