Getting text inside of a search input and give a variable the text value in javascript

Basically, there is an input tag that has the id bar, and it’s a search input.

<input id="bar" type="search">

and I tried to get the value of that input with jQuery.

var query = document.getElementById("bar");

And it opens a new tab that searches whatever you typed into the search bar into google. But it doesn’t get the text, it just says ‘undefined’. And no, I typed stuff.

Repl