<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/javascript-interview-question-why-does-9-8-7-6-1-2-7--jgma1hjsf" -->

---
title: Javascript Interview Question: Why does [9,8,7,6][1,2] = 7 ?
description: Learn why [9,8,7,6][1,2] evaluates to 7 and explore similar array operations in JavaScript.
canonical: https://daily.dev/posts/javascript-interview-question-why-does-9-8-7-6-1-2-7--jgma1hjsf
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Javascript Interview Question: Why does [9,8,7,6][1,2] = 7 ? | daily.dev
og:description: Learn why [9,8,7,6][1,2] evaluates to 7 and explore similar array operations in JavaScript.
og:url: https://daily.dev/posts/javascript-interview-question-why-does-9-8-7-6-1-2-7--jgma1hjsf
og:image: https://api.daily.dev/og/posts/jGMA1hjSf.png
og:image:alt: Javascript Interview Question: Why does [9,8,7,6][1,2] = 7 ?
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Javascript Interview Question: Why does [9,8,7,6][1,2] = 7 ?

**[Medium](https://daily.dev/sources/medium_js)** · [@rahuulmiishra](https://daily.dev/rahuulmiishra) · 1 min read · 391 upvotes · 32 comments

## Summary

Learn why [9,8,7,6][1,2] evaluates to 7 and explore similar array operations in JavaScript.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://rahuulmiishra.medium.com/javascript-interview-question-why-does-9-8-7-6-1-2-7-a8c070d46cc6>

## Community discussion

Top comments from developers on daily.dev.

**@thentech** · 53 upvotes

> The first brackets create an inline array, the second pair of brackets call the array lookup function based on index. The expression between the second brackets has the comma operator, which evaluates the first part (the 1) and then the second one (the 2) and then returns whatever the last item was. So 2 in this case. Which makes that the argument for the array lookup is 2, so the overall expression evaluates as 7, since that is the 2nd element of the inline array.

**@random\_user** · 21 upvotes

> Wouldn't you consider it a red flag if a company was asking this in a coding interview?  would any of you pass this code in a code review?  🤔 interviews are just as much for the employee to get a feel for the company as they are for the company to get a feel for the employee.

**@stannyweb** · 6 upvotes

> That's a really good info. Thank you for sharing.

**@mohammadbahmani** · 3 upvotes

> In JavaScript, when you use square brackets directly after an array, it's interpreted as accessing the element at the index specified within those brackets. Let's break down the expression `[9, 8, 7, 6][1, 2]`:
>
> 1. `[9, 8, 7, 6]`: This is an array with elements 9, 8, 7, and 6.
> 2. `[1, 2]`: This is also an array with elements 1 and 2.
>
> When you use `[1, 2]` immediately after `[9, 8, 7, 6]`, JavaScript evaluates it as an array expression. However, the comma operator in JavaScript evaluates each expression and returns the last one. In this case, it evaluates `1` and `2`, but only returns `2`. So...

**@itsjavi** · 2 upvotes

> JavaScript I hate you and I love you 🫶

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 1 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments
- [CNCF Unveils Schedule for KubeCon \+ CloudNativeCon Europe 2026](https://daily.dev/posts/cncf-unveils-schedule-for-kubecon-cloudnativecon-europe-2026-ikhcoa5cb) · CNCF · 2 upvotes · 0 comments
- [CNCF Debuts KubeCon \+ CloudNativeCon Japan 2026 Schedule](https://daily.dev/posts/cncf-debuts-kubecon-cloudnativecon-japan-2026-schedule-xp5pyudub) · CNCF · 1 upvotes · 0 comments

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#javascript](https://daily.dev/tags/javascript), [#career](https://daily.dev/tags/career), [#interview](https://daily.dev/tags/interview), [#frontend](https://daily.dev/tags/frontend)

[View this post on daily.dev](https://daily.dev/posts/javascript-interview-question-why-does-9-8-7-6-1-2-7--jgma1hjsf)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Javascript Interview Question: Why does [9,8,7,6][1,2] = 7 ?","url":"https://daily.dev/posts/javascript-interview-question-why-does-9-8-7-6-1-2-7--jgma1hjsf","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/javascript-interview-question-why-does-9-8-7-6-1-2-7--jgma1hjsf"},"datePublished":"2024-01-18T04:36:31.318Z","dateModified":"2024-01-19T01:00:09.125Z","description":"Learn why [9,8,7,6][1,2] evaluates to 7 and explore similar array operations in JavaScript.","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d5900e6d1b1a17dbfabd537141b91ae6?_a=AQAEufR","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d5900e6d1b1a17dbfabd537141b91ae6?_a=AQAEufR","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Person","name":"Rahul Mishra","url":"https://daily.dev/rahuulmiishra","image":"https://lh3.googleusercontent.com/a-/AOh14GiNTwjXeLyyPYdrj0PoI1VJ_TuEe3b5O3niL3AHd5g=s100","description":"I breathe Javascript.","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":140}},"commentCount":32,"discussionUrl":"https://daily.dev/posts/javascript-interview-question-why-does-9-8-7-6-1-2-7--jgma1hjsf","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":391},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":32}],"keywords":"webdev,javascript,career,interview,frontend","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"Javascript Interview Question: Why does [9,8,7,6][1,2] = 7 ?"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/javascript-interview-question-why-does-9-8-7-6-1-2-7--jgma1hjsf","comment":[{"@type":"Comment","text":"The first brackets create an inline array, the second pair of brackets call the array lookup function based on index. The expression between the second brackets has the comma operator, which evaluates the first part (the 1) and then the second one (the 2) and then returns whatever the last item was. So 2 in this case. Which makes that the argument for the array lookup is 2, so the overall expression evaluates as 7, since that is the 2nd element of the inline array.","datePublished":"2024-01-18T21:07:38.791Z","url":"https://daily.dev/posts/jGMA1hjSf#c-XLrz8GgEi","author":{"@type":"Person","name":"ThenTech","url":"https://daily.dev/thentech","image":"https://avatars.githubusercontent.com/u/11493646?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":53}},{"@type":"Comment","text":"Wouldn’t you consider it a red flag if a company was asking this in a coding interview?  would any of you pass this code in a code review?  🤔 interviews are just as much for the employee to get a feel for the company as they are for the company to get a feel for the employee.","datePublished":"2024-01-19T18:02:02.169Z","url":"https://daily.dev/posts/jGMA1hjSf#c-OpT5qNmYW","author":{"@type":"Person","name":"Joshua Jarman","url":"https://daily.dev/random_user","image":"https://media.daily.dev/image/upload/f_auto/v1632349791/avatars/f857f24c9be64a05bcc33d248c2e9b23"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":21}},{"@type":"Comment","text":"That’s a really good info. Thank you for sharing.","datePublished":"2024-01-19T15:54:38.894Z","url":"https://daily.dev/posts/jGMA1hjSf#c-kDPyCTYga","author":{"@type":"Person","name":"Stan","url":"https://daily.dev/stannyweb","image":"https://media.daily.dev/image/upload/s--6cFwRryH--/f_auto,q_auto/v1703580056/avatars/avatar_DfYu8ES7V9Hw07rnUoTGW"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":6}},{"@type":"Comment","text":"In JavaScript, when you use square brackets directly after an array, it’s interpreted as accessing the element at the index specified within those brackets. Let’s break down the expression [9, 8, 7, 6][1, 2]:\n\n[9, 8, 7, 6]: This is an array with elements 9, 8, 7, and 6.\n[1, 2]: This is also an array with elements 1 and 2.\n\nWhen you use [1, 2] immediately after [9, 8, 7, 6], JavaScript evaluates it as an array expression. However, the comma operator in JavaScript evaluates each expression and returns the last one. In this case, it evaluates 1 and 2, but only returns 2. So effectively, [1, 2] is interpreted as just 2.\nNow, the expression becomes [9, 8, 7, 6][2], which means you’re accessing the element at index 2 in the array [9, 8, 7, 6]. Since arrays in JavaScript are zero-indexed, the element at index 2 is 7. Hence, [9, 8, 7, 6][1, 2] evaluates to 7.\nTo clarify, if you intended to access multiple elements from the array [9, 8, 7, 6], you would need to use another approach, such as using nested arrays or iterating over the indices.","datePublished":"2024-02-28T11:19:54.433Z","url":"https://daily.dev/posts/jGMA1hjSf#c-yRDRC2691","author":{"@type":"Person","name":"Mohammad Bahmani","url":"https://daily.dev/mohammadbahmani","image":"https://media.daily.dev/image/upload/s--65uK3TaD--/f_auto/v1709363277/avatars/avatar_PxmhO8jTbrjRfRKBpNxyG"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}},{"@type":"Comment","text":"JavaScript I hate you and I love you 🫶","datePublished":"2024-02-08T20:40:21.408Z","url":"https://daily.dev/posts/jGMA1hjSf#c-1VR4O315v","author":{"@type":"Person","name":"Javier","url":"https://daily.dev/itsjavi","image":"https://media.daily.dev/image/upload/s--Lhs9VFvX--/f_auto/v1711531445/avatars/avatar_L28cJws79VJWZec5RBvoy"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}}]}
```

