> For the complete documentation index, see [llms.txt](https://sandeepamaranath.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sandeepamaranath.gitbook.io/notes/doubts-and-clarifications.md).

# Doubts and Clarifications

## Javascript

### 1. How to set an image src in JS?

In PIG Game, we set image src like this,

```javascript
document.querySelector('.img').src = "img.png"
```

The doubt is, when do we use load event since setting `img src` is async operation?

{% hint style="success" %}
If you want to do something after the image loads, the you capture load event and write the required code in a callback function.&#x20;

If you don't want to know when the image has been loaded and not interested in performing any operations after the image has been loaded then you can proceed without capturing the load event. Example below

```javascript
img.src = "test.jpg"
img.addEL('load',function(){
   console.log("The image has been fully loaded now");
})
```

{% endhint %}

### 2. Spread operator \[...] creates a shallow copy of array. Can we create a deepcopy and how? Also for objects?

{% hint style="success" %}
You can create the deep copy yourself manually but it's too much of work. Look at JavaScript notes and I've explained various ways to do that.
{% endhint %}

### 3. In react, a variable is not working that is defined outside JSX

React slider project john's milga <https://www.youtube.com/watch?v=a_7Z7C_JCyo&t=11303s&ab_channel=freeCodeCamp.orgfreeCodeCamp.org>

![](https://1944679227-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVEiPUp08kYt33g51v7%2F-MczPvfEmpgV782DbXrp%2F-MczQBlJvOFg98ExObDd%2Fimage.png?alt=media\&token=32b6725f-9ebb-4217-89a9-ac71e257f8de)
