Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140220

Why does this React component return the string '0'

$
0
0

When I write this code, I expect my React Component to display nothing. However, it displays '0'. Why is this?

import React from "react";
import ReactDOM from "react-dom";

const App = () => {
  const object = {
    array: []
  }

  return (
    <>
    {object.array && object.array.length && (
      <p>Test</p>
    )}
    </>  
  );
}

ReactDOM.render(<App />, document.getElementById("root"));

See this code sandbox for a live demo: https://codesandbox.io/s/sad-lovelace-mmrkz


Viewing all articles
Browse latest Browse all 140220


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>