Bird
0
0

Which of the following is the correct syntax to display a variable named $userName in a Blade template?

easy📝 Syntax Q3 of 15
Laravel - Views and Blade Templates
Which of the following is the correct syntax to display a variable named $userName in a Blade template?
A<code>{!! $userName !!}</code>
B<code>{{ $userName }}</code>
C<code>@{{ $userName }}</code>
D<code>[[ $userName ]]</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall Blade variable echo syntax

    Blade uses {{ }} to echo variables safely.
  2. Step 2: Analyze options

    {{ $userName }} is correct. @{{ $userName }} escapes Blade syntax for JavaScript frameworks. {!! $userName !!} outputs raw HTML. [[ $userName ]] is invalid.
  3. Final Answer:

    {{ $userName }} -> Option B
  4. Quick Check:

    Display variable = {{ $userName }} [OK]
Quick Trick: Use {{ }} to echo variables safely in Blade templates [OK]
Common Mistakes:
  • Confusing @{{ }} with normal Blade echo
  • Using {!! !!} without needing raw HTML
  • Trying invalid brackets like [[ ]]

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes