typescript document.queryselector type 1

typescript document.queryselector type

var example: Element | null = document.querySelector("whatever")

Here is what the above code is Doing:
1. We’re creating a variable called example.
2. We’re using the querySelector method to find the first element in the document that matches the CSS selector “whatever”.
3. We’re assigning the result of querySelector to the variable example.
4. We’re using the | operator to tell TypeScript that the result of querySelector could be null.

Similar Posts