Jews had not fought a single war as a cohesive people over the course of the diaspora period, excluding the Himyarites and such, and as I understand it, Jews were mostly either barred or disinterested from attending the military academies of European nations. The foundation, organization, and functioning of an effective modern army requires a great deal of specialized knowledge and education, and although the fledgling State of Israel could surely draw upon a decently sized pool of experienced soldiers, how did they find the human capital required to hold together an effective fighting force without running into the amateur ineptitudes frequently seen in armies with untrained leadership?
You might be interested in this answer, written by /u/tayaravaknin, a redditor lost to history. Another well-sourced masterpost on Israeli independence that mentions the Haganah can be found here. A closely related question is answered by Anon here.
This is a really good question, and it's one I've been itching to answer, but I've been too busy to put in significant information until now. It's very long, so I split it into multiple parts. Check out the responses to this comment for more.
The main reason why the State of Israel could create such a force revolves around the history leading up to the state's creation. A confluence of events, many of them ironic and counterproductive to those who undertook them, made Israel capable to defend itself. Briefly, the reasons for their success revolve around: 1) Arab riots; 2) WWII (and the Holocaust). Each taught lessons to Jews that helped Israel rapidly form an effective military force. Equally important to all of those, in my view, is also the ineptitude of the armies they fought in 1948, and their actions during the war itself.
The First Fights: Arab Riots
When Jews first began arriving in the area, seeking to establish communities and the foundation for a state, they weren't exactly welcomed with open arms. One early arrival wrote that the first immigrants went through significant struggles "when the Arabs attack[ed] [them]". There were many skirmishes between Arab and Jewish populations, though I don't want to give the impression it was all animosity; in the earliest days, it really wasn't.
Still, the back-and-forths inspired Jewish community leaders to form a loose self-defense organization, known as "HaShomer" (literally, "The Guard"). It drew from an organization known as Bar-Giora, drawing from Shimon Bar-Giora, a leader of the Jewish Revolt against Rome, which sought to establish Jewish communities. The motto was "In blood and fire Judea fell; in blood and fire shall Judea rise", which speaks to the sense that Jews were already beginning to feel that hostility could only be met with hostility (at least, in the area of Israel). The group was only founded around 1908, because attacks on Jewish communities had risen significantly following the 1908 Young Turks Revolt.
No more than 100 people ever joined HaShomer, which mostly concerned itself with providing security services on farms and accompanying farmers out into fields. In some ways, the guards often acted far too aggressively, viewing fear as important to establish deterrence to protect Jewish communities.
By 1911, things were continuing to deteriorate. There were increasingly numerous assaults on Jews, and murders also grew in number. The rising antagonism took some level of a backseat during WWI, when things were significantly more focused on the war itself. The British takeover of the area, and the subsequent end of the war, meant a return to strong hostility to the Jewish communities of the area, and antagonism rose among both communities once more. It seemed increasingly destined to reach some form of crisis, with the Jaffa Muslim-Christian Association saying, "We will push the Zionists into the sea--or they will send us back into the desert", and Ben-Gurion (Israel's first Prime Minister) saying that a solution was impossible, because "We, as a nation, want this country to be ours; the Arabs, as a nation, want this country to be theirs", and saying there was a gulf impossible to bridge as a result.
1919 brought some of this forward, as well. Four Jewish settlements in the Galilee area (northern Israel) and into southern Lebanon were effectively in between British and French control, but neither really had forces there. The Jewish communities wanted British control, and Bedouin tribes wanted to push out any vestiges of French control as well, and received support from the anti-French leadership in Syria (soon to be deposed by the French). The Bedouin said they didn't have any desire to harm the Jews, and were looking only to push out the French, but they fired on the Jewish community of Tel Hai and killed someone on December 12, 1919. The Jews, however, wanted neutrality, preferring not to pick sides in the fight. Soon, the Bedouin viewed this neutrality as animosity, and they began to regard the settlements as enemies, so two of the four Jewish communities wholly picked up and evacuated in 1920. Tel Hai and Kfar Gil'adi remained in place, and one of Israel's most famous war heroes Yosef Trumpeldor (who had lost an arm, and fought in both the Russo-Japanese War of 1905 and at Gallipoli) came to reinforce the villages. On March 1, 1920, the fight began, with the Bedouin beginning their assault on the two villages.
There were roughly 35 defenders at Tel Hai, another 35 at Kfar Gil'adi, and another 35 at Metulla, which had been evacuated but was repopulated by defenders. They squared off against hundreds of Bedouin attackers. One Bedouin group entered Tel Hai by saying they just wanted to check if French troops were there, and one of the Jewish guards panicked and shot at them when he saw them, resulting in a firefight. The Bedouin were sent back out, and those who had been surrounding the area began their attacks. Trumpeldor was killed in the fighting, and apocryphally said, "It is good to die for our country", a phrase that stuck in the Zionist consciousness, and both Trumpeldor and Tel Hai were idolized as examples of Jewish strength. Tel Hai was not taken despite the assault, and in the middle of the night, the defenders evacuated and went to Kfar Gil'adi, which had also withstood an assault. On March 3, all the remaining areas were abandoned, but the battle lived on.
This was picture-perfect for creating an ethos of strength. Why do I share this story? Because it leads directly into the founding of the group that formed the backbone of the IDF in 1948, and the events surrounding it.
Following the events at Tel Hai, we can finally reach the riots of the story, which began not long after. That too added to the mythos of the situation at Tel Hai. In 1920, following the Syrian King Faisal's declaration of himself as king of Syria and Palestine, demonstrations began among the Arab population hoping to join Syria. The British may have missed what would follow, but the Jewish community surely didn't. Vladimir Jabotinsky, one of the more hard-line Zionists (who believed only military success would lead to Israel's creation, and no diplomacy could result in Zionism's vision of a Jewish state), wrote on March 12 to Chaim Weizmann (Israel's first President and one of the Labour Zionists, who believed in diplomacy as a potential route to statehood) that "The pogrom is liable to break out here any day".