Can anyone help me in understanding the below code. This was asked during an interview.

console.log(a);
var a = 5;
console.log(a);
a = () => {};
console.log(a);
function a() {
}
console.log(a);

like
Posting as :
works at
You are currently posting as works at

as per as I understand output will be -
undefined
5
function body(not sure abt this)
function body

Totally based on hoisting. Have a look at "var" keyword and hoisting. Hope this helps.

like

Correct

Hi Buddy-

The output would be like this -
Function definition of a
5
Function definition of a
Function definition of a

Based upon the hoisting concept, it picked up the declaration from the bottom of the code where it defines a as a function.
Then, its definition changed to plain number 5, so it gets printed.
Next, it is just the same thing but used ES6 syntax to define a as a function. Hence, same function definition is printed.
Lastly, again it is defining a as a function and gets printed. :)

like

No, because it goes to the bottom and able to see the declaration of A defined as a function.

Were they separate? Looks like a question related to hoisting to me.

btw, excellent question I must say. Can you share me some more interview qn.s on JS. I am also giving interviews

Omg

I just want to add one more thing.. I think here the key is that function hoisting takes precedence over variable hoisting.

Almost close. Basically hoisting consider only declarations not initializations. So let's suppose, if we define console.log(a); a = 5; var a=6; then it would print a's values at each step as null, 5,6

Related Posts

What is the interview process in Grid Dynamics For QA Automation Engineer.

like

Was interviewing with a firm and soon after receiving an offer, learned of bad culture/toxic partners in the practice group from a couple of associates who recently lateraled from the firm. I turned the offer down. A partner that I clicked with while interviewing reached out asking me why I turned down the offer. Should I be honest and relay what I heard?

like

Have a first interview for an associate solution architect role next week. Should be a technical interview, as i saw the interviewer is another solution architect. Any tips on how I should prepare for this?

like

What would your reaction be if the company you applied to asked for you to get permission from your current firm before moving forward? The situation is the company you're applying to is a client of your current firm, and you've already gone through the interview process with the new company. Thoughts?

like

Next week I have two skill interviews w/ Accenture & Bioventus (both Workday positions) . Any advice / recommendations on preparation for the questions (and answers) they may ask?

like

I had a very positive experience interviewing with Amazon for an L5 Technical Writer role. I originally applied for a lower level writing role, ending up acing my Loop, and was passed on to speak to the hiring manager for the L5 role.

Given the positive tone of our conversation, I expect to receive an offer this week.

Can somebody tell me what kind of base salary/bonus/RSU ranges I should aim for? I'm transitioning to tech and have 10+ years of professional writing experience. PNW based.

like

What questions to expect in ubs UI dev interview for 4 years exp candidate. Can someone share their experience

How much can Gartner can pay me if my current CTC is around 14 No offer in hand Tech Stack - Java , Spring Boot , Microservices YOE -5.6 Position i am getting interviewed for - Senior Software Engineer

like

Interviewing for a PWC change role and coming from industry. What's the difference between a Manager and a Lead?

like

It's appalling how bad new associate excel/ppt skills are. There needs to be a way of judging 'readiness' during the interview process.

like

TCS rehiring started?
TCS HR called me and scheduled an interview even though I said I'm exTcser

like

Anyone working as a 2 years + lawyer for Fragomen in Canada can share their salaries and working advantages? (holidays, billable hours etc). Got an interview coming up and want to make sure not to under-sale my profile!

like

I JUST LANDED A PHONE INTERVIEW WITH GOOGLE!!! can I get some google phone interview tips, advice, etc.? (Forever grateful) 🙏🏾

like

Hello hive mind. I am currently interviewing with three agencies. Pretty far along with two of them. One of the positions is a Jr. copywriter position while the other two are just for a copywriter. How important would it be to not have the “Jr” before the title? Personally, I don’t care about the title, but wonder about future employer’s?

like

Is “Hacking the Case Interview” any good?

like

Hello, we've recently started a community focused on FAANG Interview preps. Wondering what kind of content people might be interested to see in such communities.

like

Anyone working for AMAT account under BIBA ?
My role is data science and iot engineer. What questions can I expect in an internal interview ?

Currently interviewing for corporate development manager at a PE portco and would appreciate insight on reasonable comp expectations. TEV is ~$4b and they close about a dozen LMM deals per year. TIA!

like

Tata Consultancy Yesterday I got call from the tcs, they told that i have cleared the interview and they will send me mail for documents upload but till now i didn't got any mail... I am trying to call back but no one is picking, can anyone suggest me how much time they'll took for sending the mail for documentation

More Posts

Anyone moved from NYC to Miami recently? I have moved over 2 months ago, still trying to adjust 🤔

like

Lol Moxy hotel is trash. Is it worth it to complain?

Post Photo
likefunny

Hi,

I am a Certified aws developer associate

8 years overall experience in Devops and scripting

I am good at python

Looking for aws python developer role.

Please let me know if there is any opportunity for me

likehelpful

Kindly help me choose one
1.
Goldman Sachs : 24 LPA (Fixed)
2. Deloitte Digital (India): 30 LPA
3. American Express: 28 LPA
Yoe: 7

I’d like to spend minimum 3-4 years in the next company.
WLB, Quality of work, Promotion, Hikes and Bonus. Sharks, your suggestion please!

like

Deloitte Consulting's M&A team is hiring IT M&A professionals for their Dubai office (United Arab Emirates, Middle East)

If interested, please reach out for more color

like

Which of the DC metro offices does Deloitte tax general sit in? McLean?

like

Operations and Strategy Manager - Google Cloud role in Chicago. What is the level, base and tc for this position? Tiy

like

After the vesting cliff do you see a lot of people exit Google?

like

Is the way to train managers changing? I’m familiar with a cohort model where a group of new managers meet in person, and then go through some classes together over a period of 2-6 months. Is there a better or new model that people are using?

like

Anyone work at a boys club? How does a female break through if you're not into politics and playing games.

like

Does anyone know of any consulting/advisory companies hiring?

funnylike

Anyone from Amazon India Finance division? Looking for an employee referral.

like

Have been struggling to context switch between different projects that I am working on simultaneously. Any tips? Thanks in advance :)

like

How did you switched to SDET. How much ds algo you prepared.

like

Any way to get in one of these IPOs prior to them opening up to the wider market?

like

Any REIT ETFs that people like?

like
like

Anyone here who made the exit from Big 4/MBB consulting to a VC? If so, I’d love to hear about how the experience is so far. (Not to mention the WLB and comp!) I’m considering a career change but have no one in my network I can go to for insights. Thx! 🙏🏾

like

Promoted to SSE with 25% hike and VP as 9% . I had received ACE award in Q3 . I have also maintained utilization report 100% still I got less VP. Can I ask manager to revisit the component

like

Any places you would recommend for a good massage in center city (not looking for happy endings)

likefunny

Additional Posts in Consulting India

gave interview at Mindtree and Infosys .
Got selected in final round with ECTC = 12L. YOE= 5.5 , CCTC = 5.1, Tech = QA Automation selenium. Want to know as per market standard can i expect more. And which to choose incase of WLB... Any thought on this...

like

Hi Fishes,
I’ve 3 offers in Hand
1) Eversana(Associate Consultant) - 13.7L fixed + 1L joining bonus
2)HSBC(Associate Consultant) - 14.5L fixed
3)Eli Lilly(Associate Consultant-CSSP) - 13.5L fixed + 1.5L variable pay

Which offer is better and which company is better?

All company locations is Bangalore

like

What do you choose between CitiusTech and KPMG (Lightouse) India?
Both Offer the Same CTC.
CitiusTech is offering Software Engineering.
KPMG is Offering Associate Consultant.
But looks like both tend be the same kind of Job profile

like

What should be the ask in Amazon for SDE 1 role ?
CCTC: 10 LPA, experience 2 years. Thanks

Hi Fishes

Is it a good idea to pursue MBA ?
I am currently earning 20LPA as a dot net developer and am confuses about going for it. Don't want to loose an income stream for a minor jump.

Can anyone here help understand the future prospects and how should I go ahead for it ?

Thnx in advance 🙏

like
like
like

Hi fishes,
Please help with 11 likes.
Thanks in advance :)

likesmart

Hi,
I have received offer from Accenture and I will be joining in couple of weeks. below is the compensation plan I got for fixed
component.Do I need to fill in the cells highlighted in yellow? What would be in hand monthly salary considering max tax savings?

Post Photo
like

Why undeserved persons,who work only for one to two hours gets promotion?

Why the Hardworking and No working people get the same hike?

How fair is this?What is the point in working hard?

like

How much percentage of amount does verizon usually pays from variable pay and when do they pay it?
I'm having 1L variable pay and going to join this month.

Is YOE 4.5 - Current CTC 17L is fair in Bengaluru in Fortune 500 company? Please provide your thoughts!

Tech stack: React, Redux. Rudux-saga, TS, CSharp, Sql

likesmart

Who gets to decide the ctc offered to a candidate? If a candidate is being offered x3 his/her current salary then does it give their manager the licence to overutilize the candidate with insane work? The way I see it there's no real benefit for the candidate here considering the performance pressure on him/her.
Thoughts?

likefunny

How is the learning and growth in IBM Bangalore? Also I have heard they don't provide yearly hikes, is it true? I have 2.3 years as a java developer.

funny

There are so many people getting offers with more than 10-15 LPA in IT by providing fake experience & proxy interview support. Some don't even have a technical degree.

I totally feel worthless now after working 5 yrs in IT now. I worked very hard, got admission in top college, studied very well there & got an offer of 10 LPA during clg placements.

I know in India unemployment is at peak but getting employed in illegal way doesn't do justice for hardworking people? Any thoughts over this ?

likefunnyhelpful

What all what is the difference between variable pay and bonus? Which one is better?


PLEASE PROVIDE YOUR INPUTS!!

like

Need help in picking between Admiral India and Conde Nast.

Tech stack MERN full stack
YOE: 5 (3 as full stack)

Admiral India:
Senior Full Stack developer
26 fixed + 5 mediclaim + Joining bonus + share + Insurance benefits

Conde Nast:
SE 2
25 fixed + 3 mediclaim + 1 joining bonus

Even though the difference in offers, I want to know from people who are/have worked there about work/culture differences or anything that I should know before making the final call.

Thanks!

like

When will be my Infosys appraisal or compensate revision if i join in April 2022? How is appraisal cycle? Infosys Tata Consultancy Accenture Cognizant IBM Wipro

How long UST Global takes to roll out offer letter after HR discussion? It has been 7 days since I submitted all the documents but haven't heard anything from them after that.

like

New to Fishbowl?

Download the Fishbowl app to
unlock all discussions on Fishbowl.
That was just a preview…
Sign Up to see all discussions
  • Discover what it’s like to work at companies from real professionals
  • Get candid advice from people in your field in a safe space
  • Chat and network with other professionals in your field
Sign up in seconds to unlock all discussions on Fishbowl.

Already a user?
Login here

Share

Embed this post

Copy and paste embed code on your site

Preview

Download the
Fishbowl app

See what’s happening in your industry
from the palm of your hand.

A phone with Fishbowl app

Scan your QR code to download
Fishbowl app on your mobile

Download app

Sign up for free to view this conversation on Fishbowl

By continuing you agree to Terms of Use and Privacy Policy

Already have an account? Log in

Sign up for free to continue using Fishbowl

By continuing you agree to Terms of Use(New) and Privacy Policy(New)
Messaging rates may apply

Already have an account? Log in

For account settings, visit Fishbowl on Desktop Browser or

General

Legal