In case you want to exclude a layer not to show up, on the LayerList then you probably don't want it appear in the Legend and Attribute Table either.
LayerList Widget
The LayerList widget through the Settings provides a way to exclude layers to be listed in the Layer List. However, if you add a layer programmatically, the layer is not listed in the Settings.
You can exclude a layer by accessing the LayerListView.js under the LayerList widget folder under the addLayerNode function and add this simple script. In this script, a layer with the text "Outside" in the title of the layer will be excluded. You can use any other layerinfo property to specify which layer to exclude.