Unable to understand this magic code

I completed my full stack certification. Now I am trying to solve data structure.
Actually I am trying to solve the linked list challenge. I understood how to write add method to add element to linked list. but I am not able to understand one thing.
This code I got from Beau from you tube.

function LinkedList() {
  var head = null
  var length = 0

  var Node = function(element) {
    this.element = element
    this.next = null

  }

  this.add = function(value) {
    var node = new Node(value)

    if (head === null) {
      head = node

    }
    else {
      var currentNode = head

      console.log(head, 'head')
      head = currentNode

      while (currentNode.next) {

        currentNode = currentNode.next
      }

      currentNode.next = node;

    }
  }
}

var conga = new LinkedList();
conga.add(1);
conga.add(2);
conga.add(3);
conga.add(4);
conga.add(5);

This is that code.
Actually if you look at this code ,you can see that
first,he assigned value for

height=null

that is okay. I know why height is assigned as a value null.
But after that you see

if (head === null) {
  head=node
}

I understood this also.
I did not understand only one thing from else block
In else block you can see he assigned

currentNode = head

but he did not assign any value in else block for head
he only assigned value for head in if block. if block will only get executed once.
but if you do console.log(head) from if block ,you can see that the value of head is getting updated.
how is it possible that one variable value is getting changed without assigning any value?
if he assigned

head=currentNode

in else block, I would not ask this question.
Can you please help this issue?

Unable to post because of it is asking ``` back ticks

There is a video on youtube from Freecode camp on data structure and algorithm.
I will just post the link of code pen of linked list code below

https://codepen.io/beaucarnes/pen/ybOvBq?editors=0011

I have only doubt in else block
Now I am concentrating only on add method.
I did not understand only one part from else block.
in if block variable head is assigned with the value of node. but in if block there is a condition that if head is equal to null , then only if block will get executed. as the value of head at the first time, this if block will get executed once. after that the value of head is not null. so if you call the method after first time, this if block wont get executed.
you can see that we did not assign any value for the variable head in else block. we only assign the value in if block for head. but if you do
console.log(head)
from else block, you can see that each time you add the value to linked list , the value of head is also getting changed. that part I did not understand

I think if the value of head is to be changed, that if block should get executed. but that will only executed once. then how the value of head is getting changed each time we call add method

console.log I used there for understanding how the value of variable head is getting changed.
Hope you help me solving my doubt

Thank you for replaying. But I did not understand properly
var currentNode = head
here we assign the value of head to curretNode. So that currentNode variable value will get updated each time invoking the method add.

Are you saying that the value of head variable getting changed from if block or else block. Please tell me. I am worried as I am not able to understand this part.;

There is a method
this.elementAt
which use for getting the value out from linked list. if you check that, you can see that linked list values is getting stored in head?
I only want to know where that assignment part going on so that the value of head is getting changed. Can you please post that code here.? Can you please tell me whether the value of head is getting changed from if block or else block.

with all due respect let me say that I dont think this code
var currentNode = head
is the reason for getting the value of head is upadated.
To verify that I declare one more variable. confirmation which you can see in the code.
then in if block, I just assign
confirmation=node

and in else block I just do
console.log(confirmation) and found that the value of confirmation is also getting changed.(confirmation value and head value were found equal !)
So my final assumption is that , if the value of confirmation is getting changed, that happen from if block. but I don’t know know’
I am extremely sorry to ask you again and again. I don’t have any other forum expect freecoddecamp to ask my doubts.

  var head = null
var confirmation=null
  var length = 0

  var Node = function(element) {
    this.element = element
    this.next = null

  }

  this.add = function(value) {
    var node = new Node(value)

    if (head === null) {
      head = node
confirmation=node
    }
    else {
      var currentNode = head
console.log(confirmation)
      console.log(head, 'head')
      head = currentNode

      while (currentNode.next) {

        currentNode = currentNode.next
      }

      currentNode.next = node;

    }
  }
}

var conga = new LinkedList();
conga.add(1)
conga.add(2)
conga.add(3)
conga.add(4)
conga.add(5);```

Thanks for helping me.
where should we use linked list? Because in JavaScript we can store how many
element we want to push to array, we can do that dynamically. in java As we can not change the length of array, linked list is an option to store data dynamically?
So Can you please tell me this linked list , Binary search tree, avl tree is requred in JavaScript also? can you tell me the application of these types of data structure?