What best practices should be followed when initializing variables in JavaScript functions, especially when used for iframe manipulation in PHP websites?

When initializing variables in JavaScript functions for iframe manipulation in PHP websites, it is important to ensure that the variables are properly declared and initialized to prevent any unexpected behavior or errors. It is recommended to use the "var" keyword to declare variables within the function scope and assign initial values if needed. Additionally, it is good practice to check for the existence of variables before using them to avoid potential issues.

<script>
function manipulateIframe() {
    var iframe = document.getElementById('myIframe');
    
    if (iframe) {
        // Code to manipulate the iframe
    } else {
        console.error('Iframe not found');
    }
}
</script>