<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/is-javascript-pass-by-value-or-pass-by-reference--c7qiyxqa0" -->

---
title: Is JavaScript pass-by-value or pass-by-reference?
description:  JavaScript is always pass-by-value. This means everything in JavaScript is a value type and function arguments are always passed by value. That being said,...
canonical: https://daily.dev/posts/is-javascript-pass-by-value-or-pass-by-reference--c7qiyxqa0
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Is JavaScript pass-by-value or pass-by-reference? | daily.dev
og:description:  JavaScript is always pass-by-value. This means everything in JavaScript is a value type and function arguments are always passed by value. That being said,...
og:url: https://daily.dev/posts/is-javascript-pass-by-value-or-pass-by-reference--c7qiyxqa0
og:image: https://api.daily.dev/og/posts/c7QiyXqA0.png
og:image:alt: Is JavaScript pass-by-value or pass-by-reference?
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.

# Is JavaScript pass-by-value or pass-by-reference?

**[30 seconds of code](https://daily.dev/sources/30seconds)** · 1 min read · 43 upvotes · 6 comments

## Summary

JavaScript is always pass-by-value. This means everything in JavaScript is a value type and function arguments are always passed by value. That being said, object types are a bit more confusing. Object types are reference types which are passed byvalue. The subtle difference here lies in the fact that an object reference is not the same as passing an object by reference.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.30secondsofcode.org/articles/s/javascript-pass-by-reference-or-pass-by-value>

## Community discussion

Top comments from developers on daily.dev.

**@snowmonkey** · 2 upvotes

> The issue is that this is wrong. The original variable refers to a memory location, and passes that memory location to the function. Then, when the original variable is *redirected* to reference a new memory location... the function still keeps the reference to the original location.
>
> So variables are references, they pass references, and when the are redefined, the reference itself is changed.

**@ozanx** · 1 upvotes

> It has a good explanation about pass-by-value/pass-by-reference. Thanks.

**@iamfaruk** · 0 upvotes

> everyone should know.. nice article

**@ugur136** · 0 upvotes

> need more details and examples

**@guilhermevalle** · 0 upvotes

> AWESOME!

---

Tags: [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/is-javascript-pass-by-value-or-pass-by-reference--c7qiyxqa0)

```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":"Is JavaScript pass-by-value or pass-by-reference?","url":"https://daily.dev/posts/is-javascript-pass-by-value-or-pass-by-reference--c7qiyxqa0","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/is-javascript-pass-by-value-or-pass-by-reference--c7qiyxqa0"},"datePublished":"2021-12-05T18:45:02.124Z","dateModified":"2021-12-05T18:45:02.125Z","description":" JavaScript is always pass-by-value. This means everything in JavaScript is a value type and function arguments are always passed by value. That being said,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6433d1377ad7f534b336f6d92b11e0fb","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6433d1377ad7f534b336f6d92b11e0fb","isAccessibleForFree":true,"articleSection":"30 seconds of code","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":"Organization","name":"30 seconds of code","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/197d6538eea141d7a2fb4177234e9d89","url":"https://daily.dev/sources/30seconds"},"commentCount":6,"discussionUrl":"https://daily.dev/posts/is-javascript-pass-by-value-or-pass-by-reference--c7qiyxqa0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":43},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":6}],"keywords":"javascript","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"30 seconds of code","item":"https://daily.dev/sources/30seconds"},{"@type":"ListItem","position":3,"name":"Is JavaScript pass-by-value or pass-by-reference?"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/is-javascript-pass-by-value-or-pass-by-reference--c7qiyxqa0","comment":[{"@type":"Comment","text":"The issue is that this is wrong. The original variable refers to a memory location, and passes that memory location to the function. Then, when the original variable is redirected to reference a new memory location… the function still keeps the reference to the original location.\nSo variables are references, they pass references, and when the are redefined, the reference itself is changed.","datePublished":"2021-12-06T02:11:40.716Z","url":"https://daily.dev/posts/c7QiyXqA0#c-i4W4-JTH_","author":{"@type":"Person","name":"Toby Parent","url":"https://daily.dev/snowmonkey","image":"https://media.daily.dev/image/upload/v1673892598/avatars/avatar_cl-7snkow.jpg"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"It has a good explanation about pass-by-value/pass-by-reference. Thanks.","datePublished":"2021-12-05T21:03:21.900Z","url":"https://daily.dev/posts/c7QiyXqA0#c-vpg6NCTlP","author":{"@type":"Person","name":"ozan kurucu","url":"https://daily.dev/ozanx","image":"https://lh3.googleusercontent.com/a-/AOh14GhXJMvrr4yB4lz9vHMqXLjFDWdscENTOwU9vZQP=s100"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"everyone should know… nice article","datePublished":"2022-02-13T14:26:07.972Z","url":"https://daily.dev/posts/c7QiyXqA0#c-oB1Z7fjLn","author":{"@type":"Person","name":"Faruk Mnts","url":"https://daily.dev/iamfaruk","image":"https://lh3.googleusercontent.com/a-/AOh14GjlbV1LYt4kXjpTq9v_KqcG9Ht9uiZdPGCFXCmbug=s100"}},{"@type":"Comment","text":"need more details and examples","datePublished":"2021-12-06T05:38:20.054Z","url":"https://daily.dev/posts/c7QiyXqA0#c-xgp6QuS-b","author":{"@type":"Person","name":"Ugur","url":"https://daily.dev/ugur136","image":"https://avatars.githubusercontent.com/u/24832986?v=4"}},{"@type":"Comment","text":"AWESOME!","datePublished":"2021-12-06T14:14:00.975Z","url":"https://daily.dev/posts/c7QiyXqA0#c-u2aHuHVOs","author":{"@type":"Person","name":"Guilherme Oliveira do Valle","url":"https://daily.dev/guilhermevalle","image":"https://avatars.githubusercontent.com/u/26411012?v=4"}}]}
```

