Mystic behavior of bounce2 library and Serial output

Hi,
sorry, but I really can't name this topic. I'm trying to explain what happens with my sketch.
(Arduino nano, win10 x64, ARDUINO 1.8.1 )

I'm implementing menu on arduino controlled by several buttons. Variable ButtonPressed shows which button was pressed. ButtonHandler procedure does some depending on ButtonPressed.

Here is minimal part of my code:

 js1Click.update(); //update bounce2 object - js1 is one of the buttons
 Serial.println(js1Click.read()); //this outputs garbage to the serial port = "?b???????En?"
 if (js1Click.fell()) { FellTime = millis(); }
 if (js1Click.rose()) { //this is to detect long click
      RoseTime = millis();
      if (RoseTime - FellTime < btLongPressLatency) { ButtonPressed = btJs1Click; }
      else { ButtonPressed = btJs1LongClick; }
 }

 if (ButtonPressed == 0) { //reset counters if nothing was pressed
    btTimeNoPress = millis(); 
    btWasChecked = false; 
    btRepeatTimePress = 0;
 }

 if (ButtonPressed) { //do what i need depending on what was pressed
   // Serial.println(ButtonPressed);
    if (!btWasChecked) {
       ButtonHandler(); 
       btWasChecked = true;
       btRepeatTimePress = 0;
    }
}

Compiler output

Compiling 'Rewinder_Peter' for 'Arduino Nano w/ ATmega328'
Program size: 14,240 bytes (used 46% of a 30,720 byte maximum) (1.39 secs)
Minimum Memory Usage: 630 bytes (31% of a 2048 byte maximum)
 

AVR Memory Usage
----------------
Device: atmega328p

Program:   14240 bytes (43.5% Full)
(.text + .data + .bootloader)

Data:        630 bytes (30.8% Full)
(.data + .bss + .noinit)

text   data    bss    dec    hex 
      0  14240      0  14240   37a0

If I remove

Serial.println(js1Click.read());

this part of sketch doesn't work at all. I.e js1Click.update(); doesn't work and ButtonPressed = 0

If I uncomment

Serial.println(ButtonPressed);

Serial.println(js1Click.read()) prints 1 instead of garbage (as button is really not pressed) and this part of sketch doesn't work as well.

Your code is very hard to read for several reasons.

Put EVERY { on a line BY ITSELF.
Put EVERY } on a line BY ITSELF.
Use Tools + Auto Format.

Post ALL of your code.

The presence, or absence, or Serial.print() statements affecting the rest of the code almost always comes down to running out of memory.

http://playground.arduino.cc/Code/AvailableMemory

Good function names consist of a verb (what to do) and a noun (what to do it to). ButtonHandler() is a louse name. handleButton() isn't much better, but at least it has a noun and a verb. Describing exactly what "handle" means would be far better.

Dear PaulS, many thanks, noted.