?Assigning Api resposne to a variable undefined error

I am getting undefined for variable d; even console.log(res.data.results[0]) is working fine

import ‘./App.css’;
import a from ‘axios’

function App() {
let d;
a.get(“https://randomuser.me/api/”)
.then(res => {
//console.log(res.data.r…


This content originally appeared on DEV Community and was authored by HAFIZ ABDULMANAN

I am getting undefined for variable d; even console.log(res.data.results[0]) is working fine

import './App.css';
import a from 'axios'


function App() {
  let d;
  a.get("https://randomuser.me/api/")
  .then(res => {
    //console.log(res.data.results[0])
    d = res.data.results[0]
  })
  .catch(err => console.log("Its en error"))

  console.log(d) // undefined

  return (
    <div className="App">

    </div>
  );
}

export default App;


This content originally appeared on DEV Community and was authored by HAFIZ ABDULMANAN


Print Share Comment Cite Upload Translate Updates
APA

HAFIZ ABDULMANAN | Sciencx (2022-07-20T09:55:33+00:00) ?Assigning Api resposne to a variable undefined error. Retrieved from https://www.scien.cx/2022/07/20/assigning-api-resposne-to-a-variable-undefined-error/

MLA
" » ?Assigning Api resposne to a variable undefined error." HAFIZ ABDULMANAN | Sciencx - Wednesday July 20, 2022, https://www.scien.cx/2022/07/20/assigning-api-resposne-to-a-variable-undefined-error/
HARVARD
HAFIZ ABDULMANAN | Sciencx Wednesday July 20, 2022 » ?Assigning Api resposne to a variable undefined error., viewed ,<https://www.scien.cx/2022/07/20/assigning-api-resposne-to-a-variable-undefined-error/>
VANCOUVER
HAFIZ ABDULMANAN | Sciencx - » ?Assigning Api resposne to a variable undefined error. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/20/assigning-api-resposne-to-a-variable-undefined-error/
CHICAGO
" » ?Assigning Api resposne to a variable undefined error." HAFIZ ABDULMANAN | Sciencx - Accessed . https://www.scien.cx/2022/07/20/assigning-api-resposne-to-a-variable-undefined-error/
IEEE
" » ?Assigning Api resposne to a variable undefined error." HAFIZ ABDULMANAN | Sciencx [Online]. Available: https://www.scien.cx/2022/07/20/assigning-api-resposne-to-a-variable-undefined-error/. [Accessed: ]
rf:citation
» ?Assigning Api resposne to a variable undefined error | HAFIZ ABDULMANAN | Sciencx | https://www.scien.cx/2022/07/20/assigning-api-resposne-to-a-variable-undefined-error/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.