Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Cannot access 'variable_name' before initialization

$
0
0

When using reactive variables by declaring them using the $: syntax, you get the following error.

Cannot access 'variable_name' before initialization

Here is the code:

App.svelte

<script>    import { ledzep, redhotchilis } from './data.js'    $: bandmembers = [...ledzep, ...redhotchilis]    let namesWithA = bandmembers.filter(d => {            if (d.indexOf('a') > 0) {                               return true;            }        else {            return false        }    })</script><h2>Band Members</h2><ul>{#each bandmembers as member}<li>{member}</li>{/each}</ul><h2>Members with "A" in their names</h2><ul>{#each namesWithA as member}<li>{member}</li>{/each}</ul>

data.js

export const ledzep = ["Jimmy Page", "John Bonham", "Robert Plant", "John Paul Jones"]export const redhotchilis = ["Anthony Kiedis", "Flea", "Chad Smith", "Josh Klinghoffer"]

Viewing all articles
Browse latest Browse all 1541

Trending Articles



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