0
0
NextJSframework~20 mins

Image component and optimization in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Next.js Image Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Next.js Image component?

Consider this Next.js Image component usage:

import Image from 'next/image';

export default function Avatar() {
  return (
    <Image
      src="/avatar.png"
      alt="User Avatar"
      width={100}
      height={100}
      priority
    />
  );
}

What does the priority prop do here?

AIt forces the image to load immediately during page load for better performance.
BIt makes the image load lazily only when it enters the viewport.
CIt disables image optimization and serves the raw image file.
DIt automatically adds a blur placeholder before the image loads.
Attempts:
2 left
💡 Hint

Think about what helps important images load faster on the page.

📝 Syntax
intermediate
2:00remaining
Which option correctly uses the Next.js Image component with a remote URL?

You want to display an image from https://example.com/photo.jpg using Next.js Image component. Which code snippet is correct?

A<Image src="https://example.com/photo.jpg" alt="Photo" sizes="300x200" />
B<Image src="https://example.com/photo.jpg" alt="Photo" width="300" height="200" />
C<Image src="https://example.com/photo.jpg" alt="Photo" width={300} height={200} />
D<Image src="https://example.com/photo.jpg" alt="Photo" layout="fixed" />
Attempts:
2 left
💡 Hint

Remember the width and height props must be numbers, not strings.

🔧 Debug
advanced
2:00remaining
Why does this Next.js Image component throw an error?

Look at this code snippet:

import Image from 'next/image';

export default function Logo() {
  return (
    <Image
      src="/logo.svg"
      alt="Company Logo"
      width={null}
      height={50}
    />
  );
}

What error will this cause and why?

ATypeError because width cannot be null; it must be a number.
BSyntaxError because JSX tags are not closed properly.
CRuntime error because SVG images are not supported by Next.js Image.
DNo error; the image will render with width auto and height 50.
Attempts:
2 left
💡 Hint

Check the type requirements for width and height props.

state_output
advanced
2:00remaining
What is the rendered output of this Next.js Image with layout='fill'?

Consider this component:

import Image from 'next/image';

export default function Background() {
  return (
    <div style={{ position: 'relative', width: '400px', height: '300px' }}>
      <Image
        src="/background.jpg"
        alt="Background"
        layout="fill"
        objectFit="cover"
      />
    </div>
  );
}

What will you see on the page?

AThe image does not render because layout='fill' requires explicit width and height.
BThe image displays at its original size inside the div, possibly overflowing.
CThe image is stretched to 400x300 but may distort aspect ratio.
DThe image fills the 400x300 div, cropping if needed, covering entire area.
Attempts:
2 left
💡 Hint

Think about how layout='fill' and objectFit='cover' work together.

🧠 Conceptual
expert
2:00remaining
Which statement about Next.js Image optimization is true?

Choose the correct statement about how Next.js optimizes images using the Image component.

ANext.js automatically converts all images to WebP format regardless of browser support.
BNext.js optimizes images by resizing, lazy loading, and serving modern formats based on browser support.
CNext.js serves optimized images only for local files, remote images are not optimized.
DNext.js requires manual configuration to enable any image optimization features.
Attempts:
2 left
💡 Hint

Think about what Next.js does automatically and what requires config.