New XIAO's digital read oscillates instead of consistently reading high when input pin & ground are not connected

I am totally new to microcontrollers & electronics.
I have 2 wires, 1 from ground & 1 from pin 6. When they are touching (either directly or through a pushbutton), I digitalRead LOW, but when they are not connected, the reading constantly switches between HIGH & LOW. On no delay, it stays on 0 for a while when 1 for a while and with a delay it visibly switches from oscillating to staying with one of the levels for a bit.
This means that even the most basic example code does not work, which I assume expects to read HIGH consistently when the pins are not connected.

const int buttonPin = 6;

void setup() {
  pinMode(buttonPin, INPUT);
  Serial.begin(115200);
}

void loop() {
  Serial.println(digitalRead(buttonPin));
  delay(10);
}

Nowadays, many (most) logic families have the property that “floating” input pins create undefined logic states.

That is, subject to the vagaries of enviroment (“random” noise, electric fields from mains power, cosmic rays, or whatever…), unconnected pins may look like a logic ‘1’ or a logic ‘0’ at any given time and the opposite state at some other (unpredictable) time.

You can connect an external resistor to a supply rail (Vdd or GND) to give it a known value, then connect a switch to the opposite rail to make it change to the opposite known state.

For CPUs used on Arduino boards, you can tell them to connect an internal pullup resistor by changing your mode statement to:

    pinMode(buttonPin, INPUT_PULLUP);

Now if your buttonPin is not connected to anything, it will read a logic ‘1’
When you connect your buttonPin to GND, it will read a logic ‘0’

Finally: It is not recommended to actually touch the wire from your buttonPin because static electricity can damage the processor. It might or it might not, but I definitely would not recommend it. Use a switch.

Regards,

Dave

Reference: https://www.arduino.cc/en/Tutorial/DigitalInputPullup