1

I need to add "use strict"; in this code . when I try to add it stops working, this is a js of a responsive navigation menu

<script>
     $(function() {
        "use strict";
            var pull        = $('#pull');
                menu        = $('nav ul');
                menuHeight  = menu.height();

            $(pull).on('click', function(e) {
                e.preventDefault();
                menu.slideToggle();
            });

            $(window).resize(function(){
                var w = $(window).width();
                if(w > 320 && menu.is(':hidden')) {
                    menu.removeAttr('style');
                }
            });
        });

    </script>
1
  • What's the error message? Commented Feb 14, 2014 at 7:01

1 Answer 1

4

You're creating global variables due to a syntax mistake. In strict mode these throw a reference error as the variable hasn't been declared:

var pull = $('#pull'), //<-- comma
    menu = $('nav ul'), //<-- comma
    menuHeight = menu.height();
Sign up to request clarification or add additional context in comments.

3 Comments

+1 If you view this in chrome's console window, it will actually give you the error: ReferenceError: menu is not defined
@jasonscript: I like Opera's error message better: Assignment to unresolved reference in strict mode code: menu
@Bergi: that is better. My point was that if you're checking the console, you'll see the error and it's pretty straightforward to resolve this yourself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.