For the Jews, salvation was by obedience: your works showed that you believed in God, and that earned you salvation (see, for example, Proverbs 11:18).
But when Jesus came, he taught them something new: salvation by grace and faith. A key verse in this regard is Luke 17:10 (NIV):
So you also, when you have done everything you were told to do, should say, ‘We are unworthy servants; we have only done our duty.’
See also Paul’s comments about faith and works in Romans 9:30-33.
It was hard for the Jews to accept salvation by faith and grace. How did it work? How could you tell if someone was really a believer? Maybe you didn’t even have to pretend to do the right thing. Would you be saved by grace if you just claimed to be? This is the background to James’s comments, and the source of his comment in v18 (NIV):
But someone will say, “You have faith; I have deeds” (James 2:18),
along with the comments that follow about Abraham and Isaac. Yes, you are saved by grace, through faith. But only real faith — you can’t just claim to be saved because you believe Jesus: you have to make it real in your life and do something about it. You have to demonstrate your faith in the things you do — your works. Otherwise your faith is dead — and so will you be.