title: How to take user Id when using "createUserWithEmailAndPassword(email, password)" in javascript and firebase
body: <p>I am creating new web app using firebase and javascript. To be more precise, I registered new user with <code>\firebase.auth().createUserWithEmailAndPassword(email, password)</code> It is working, but when I used this keyword I want to take UID of a new user and initialize it to a new variable at that moment. After this, I want to add new user in database using this key UID(i.e. name, age and etc.) I tried to show it using <code>console.log(user.uid)</code> as well in the browser but it is showing undefined. Please help me.</p>
  
  <p><code>Code.html</code></p>
  
  <pre><code>&lt;input type="email" id="txtEmail" placeholder="username"&gt;
  &lt;input type="email" id="txtPass" placeholder="password"&gt;
  
  &lt;button id="btnSignUp" type="submit" onclick="Press()"&gt; SignUp&lt;/button&gt;
  
  &lt;script src="https://www.gstatic.com/firebasejs/5.2.0/firebase.js"&gt;&lt;/script&gt;
  &lt;script &gt;
          // Initialize Firebase
    var config = {
      apiKey: "api key",
      authDomain: "bigpro-c6a4c.firebaseapp.com",
      databaseURL: "https://bigpro-c6a4c.firebaseio.com",
      projectId: "bigpro-c6a4c",
      storageBucket: "",
      messagingSenderId: "id"
    };
    firebase.initializeApp(config);
  &lt;/script&gt;
  
  &lt;script&gt;
       function Press(){
  
    var txtEmail = document.getElementById('txtEmail');
    var txtPass = document.getElementById('txtPass');
    var txtEmail = document.getElementById('txtEmail');
    var txtPass = document.getElementById('txtPass');
  
      var email = txtEmail.value;
      var password=txtPass.value;
    firebase.auth().createUserWithEmailAndPassword(email, password)
          .then(function(user){
            // console.log('uid',user.uid);
            console.log(user.uid);
          }).catch(function(error) {
  
          });
  
  }
  
  &lt;/script&gt;
  </code></pre>