In the book of 1st John, John discusses that God is light, and that we should follow His commands (I John 1:1-2:6), that we should be aware of false teachers (I John 2:15-29), and he contrasted between the righteous and the wicked (I John 3:1-16). In I John 3:19-24, John wants the Christians to understand that they can have assurance in their faith and their remaining in God, and if they love in deed and truth, they can have that assurance (I John 3:19). John indicates that if our heart does not condemn us, we can have confidence before God (I John 3:21). However, even if we ignore our conscience and sin, or can sin without offending the conscience, God is greater than the feelings in our heart, and He will not miss the deeds that we have done (John 12:48)! Therefore, the goal is to have a heart that does not condemn us, which is a conscience properly trained according to God's will, and living according to His will.
This is the basis of our confidence before God: not that we can earn his favor, but that we stand before Him in “the faith” (Eph 2:8-9) in His Son while we are striving to do His will. John already assumes this regarding the Christians to whom he is writing, and believes they are actively following God's commandments and are seeking to please Him. Therefore, because they are seeking God’s will, whatever they ask, they receive from Him (I John 3:22). John also informs us regarding that commandment: to believe in Jesus His Son and to love one another (I John 3:23). John makes clear that those who keep God's commandments abide in God, and God in him, and that we can have assurance of God's presence in us through the Spirit whom He has given us (I John 3:24; cf. I John 2:2-6, 27). Unfortunately, many may read that "whatever we ask from Him we receive" and then believe that they can ask God for things outside of His will and will then receive it. However, By saying that "whatever we ask we receive," John is indicates that all the things we seek which provide spiritual benefit and are consistent with God's purposes will be given (cf. Matthew 7:7, James 1:5-8). John's reassurance to the Christians is based in God's power and sovereignty, but also in one’s obedience to God. There is no reason for the Christian today to be left in doubt: let us keep God's commandments and abide in Him (1 John 5:3)!