• debuggingLifee Profile Picture

    Maahi 🌸 @debuggingLifee

    a year ago

    #javascript Interview question: what's the output of below code and comment out why?

    debuggingLifee tweet picture

    224 22 506 111K 127
    Download Image
  • davepl1968 Profile Picture

    Dave W Plummer @davepl1968

    a year ago

    @agr_manisha10 This code has a side effect: me questioning the company.

    5 2 125 12K 0
  • vedugudev Profile Picture

    VeduGudeV @vedugudev

    a year ago

    @agr_manisha10 The answer to these questions should be, I don’t want to work for a company that has code like this in their code base. Merge request rejected.

    3 2 99 7K 0
  • tech_D_coded Profile Picture

    Tech Decoded @tech_D_coded

    a year ago

    @agr_manisha10 I think the output should be 1 1 This is because the var declarations are hoisted to the top. When the function does not get a, it will look out of local scope and find a in the global scope and print that value.

    5 0 38 7K 0
  • Jno_Aubrey Profile Picture

    Jack Aubrey @Jno_Aubrey

    a year ago

    @agr_manisha10 10 1 scope matters

    8 0 23 7K 2
  • areyychandu Profile Picture

    Masudi Chandrasekhar @areyychandu

    a year ago

    @agr_manisha10 I got output as 10 and 1 can anyone make me understand why it is 10 and 1

    12 0 10 7K 1
  • iAmStillWorthyy Profile Picture

    Mohammad Sohail Ansari @iAmStillWorthyy

    a year ago

    @agr_manisha10 Due to variable hoisting, the variable 'a' will came on top of the its scope and value undefined will be stored in it. Since undefined is false statement and with ! operation its opposite will be true. Hence, the if statement will be executed and 10 will be assign to it. 10, 1.

    1 1 7 1K 0
  • mrtechsense Profile Picture

    Ripudaman @mrtechsense

    a year ago

    @agr_manisha10 Orange

    1 0 6 4K 0
  • Archivebizzlee Profile Picture

    Kumar Apoorva @Archivebizzlee

    a year ago

    @agr_manisha10 10 1

    1 0 5 4K 0
  • IsrgRajan Profile Picture

    Isrg Rajan @IsrgRajan

    a year ago

    Ah, this code? It's a delightful puzzle box of confusion! Inside the function, a plays hide-and-seek with hoisting, while outside, it proudly displays its 1. It's like a riddle wrapped in a mystery inside an enigma, all summed up in the beautiful chaos of undefinedness. Brilliant!

    1 0 4 3K 0
  • philtrem22 Profile Picture

    Philippe Tremblay @philtrem22

    a year ago

    @agr_manisha10 Nice one. Terrible interview question though.

    1 0 3 3K 0
  • gpkabk Profile Picture

    𝑨𝒎𝒂𝒏 𝑩𝒖𝒓𝒏𝒘𝒂𝒍 @gpkabk

    a year ago

    @agr_manisha10 Var is fuction scope so when we calling the function a is getting hoisted but its value will be undefined. Undefined is a falsy value so !a will be true so now a = 10 As a result we will get 10 and 1

    0 0 3 641 0
  • steadycursor Profile Picture

    Steady Cursor @steadycursor

    a year ago

    @agr_manisha10 I would not expect from new hire to tell me what is the output, but explain why is code poorly written and hot to refactor it. Anyway it should be 1 and 1. Why? Check if statement.

    1 0 3 551 0
  • webwithaman Profile Picture

    Aman Kumar @webwithaman

    a year ago

    @agr_manisha10 10 1 !undefined -> true then a = 10

    0 0 3 368 0
  • hanzaladotxyz Profile Picture

    hadi.xyz → ethglobal @hanzaladotxyz

    a year ago

    @agr_manisha10

    hanzaladotxyz tweet picture

    0 0 3 188 1
    Download Image
  • DSBrenchley Profile Picture

    David S Brenchley @DSBrenchley

    a year ago

    @agr_manisha10 1

    1 0 2 4K 0
  • AaryanBajaj18 Profile Picture

    Aaryan Bajaj @AaryanBajaj18

    a year ago

    @agr_manisha10 1 1 because of scoping of var

    0 0 2 407 0
  • me_safwan_07 Profile Picture

    Muhammed Safwan @me_safwan_07

    a year ago

    @agr_manisha10 The output of this code will be: 10 1 #javascript #Quiz

    0 0 2 38 0
  • uginemedia Profile Picture

    U-GINE MEDIA @uginemedia

    a year ago

    @agr_manisha10 1 1

    1 0 2 57 0
  • Michael_cmd_sys Profile Picture

    Michael Awuni @Michael_cmd_sys

    a year ago

    @agr_manisha10 10. This is due to variable hoisting esp. with the identifier `var`. Variables declared outside the function are not accessible within the function but the var within the function gets hoisted up into the if statement where it has a value of undefined.

    1 0 2 449 0
  • Tom_Marien Profile Picture

    Tom Marien 🇧🇪 🦋 @Tom_Marien

    a year ago

    @agr_manisha10 The thing that bothers me is you using the word interview. If you ask these questions I’ll run out to keep my sanity

    1 0 2 757 0
  • santattech Profile Picture

    Santanu Bhattacharya @santattech

    a year ago

    @agr_manisha10 10 1 reason: scope

    0 0 2 114 0
  • agrawalanuj018 Profile Picture

    Anuj Agrawal @agrawalanuj018

    a year ago

    @agr_manisha10 1 1 will be the output of this code because if condition is never gonna be run because by default a is true which makes !a false, so it only run console.log in that function.

    1 0 2 1K 0
  • MijanRichard Profile Picture

    Mijan | Web Developer @MijanRichard

    a year ago

    @agr_manisha10 function data() { var a; if (!a) { a = 10; } console.log(a); } var a; a=1 data() console.log(a) this is the way the compiler breaks it down innit. the answer will always be "10" and "1" respectively. Scope rules

    0 0 2 131 0
  • arpit_036 Profile Picture

    Arpit @arpit_036

    a year ago

    @agr_manisha10 1 1

    0 0 2 295 0
  • cameronolivier Profile Picture

    cam 🏴‍☠️ @cameronolivier

    a year ago

    @agr_manisha10 I did the second half: //why

    0 0 1 114 0
  • ChuckJorda34974 Profile Picture

    Chuck Jordan @ChuckJorda34974

    a year ago

    @agr_manisha10 I don't know what the code does. But I commented out why. //why

    0 0 1 10 0
  • codewithpsr Profile Picture

    Pranjal Singh @codewithpsr

    a year ago

    @agr_manisha10 10 1

    0 0 1 6 0
  • iRahul_Devadiga Profile Picture

    Rahul R Devadiga @iRahul_Devadiga

    a year ago

    @agr_manisha10 So it's print's 10. However outside the function the global variable stays unaffected so it print's 1 (2/2)

    0 0 1 17 0
  • Sharmavicky_93 Profile Picture

    Vicky Sharma @Sharmavicky_93

    a year ago

    @agr_manisha10 It's giving error not printing even 1 also

    0 0 1 36 0
  • BoluShobola Profile Picture

    @ bolu of lagos_ @BoluShobola

    a year ago

    @agr_manisha10 Inside the function call a change its state to be 10 because values are copied by their number/value, also the object is not stored in memory. once a goes outside of the callback it returns it value to be 1 like that of the console.log after the function call.

    0 0 1 63 0
  • lokendra_x Profile Picture

    lokendra.X @lokendra_x

    a year ago

    @agr_manisha10 10 and 1

    0 0 1 104 0
  • _sonaligpt Profile Picture

    Sonali Gupta @_sonaligpt

    a year ago

    @agr_manisha10 Good one. I thought its 1,1. Another tricky output question I once got- Output of: {}=={}

    0 0 1 22 0
  • AnkitYadav55213 Profile Picture

    Ankit Yadav @AnkitYadav55213

    a year ago

    @agr_manisha10 it give 10 and 10 because var is a local scope datatype. it can be updated and also redefined

    0 0 1 287 0
  • kapildadhich075 Profile Picture

    Kapil Dadhich @kapildadhich075

    a year ago

    @agr_manisha10 10 1 Scope matters

    0 0 1 12 0
  • Download Image
    • Privacy
    • Term and Conditions
    • About
    • Contact Us
    • TwStalker is not affiliated with X™. All Rights Reserved. 2024 www.instalker.org

    twitter web viewer x profile viewer bayigram.com instagram takipçi satın al instagram takipçi hilesi twitter takipçi satın al tiktok takipçi satın al tiktok beğeni satın al tiktok izlenme satın al beğeni satın al instagram beğeni satın al youtube abone satın al youtube izlenme satın al sosyalgram takipçi satın al instagram ücretsiz takipçi twitter takipçi satın al tiktok takipçi satın al tiktok beğeni satın al tiktok izlenme satın al beğeni satın al instagram beğeni satın al youtube abone satın al youtube izlenme satın al metin2 metin2 wiki metin2 ep metin2 dragon coins metin2 forum metin2 board popigram instagram takipçi satın al takipçi hilesi twitter takipçi satın al tiktok takipçi satın al tiktok beğeni satın al tiktok izlenme satın al beğeni satın al instagram beğeni satın al youtube abone satın al youtube izlenme satın al buyfans buy instagram followers buy instagram likes buy instagram views buy tiktok followers buy tiktok likes buy tiktok views buy twitter followers buy telegram members Buy Youtube Subscribers Buy Youtube Views Buy Youtube Likes forstalk postegro web postegro x profile viewer