Permalink
Browse files

statements

  • Loading branch information...
1 parent 18423c0 commit 61cbd3c16e6483232b6dcb53bcc7f4bc4e48a744 @namman namman committed Oct 13, 2013
Showing with 67 additions and 0 deletions.
  1. +67 −0 jsl/resources/tests.js
View
@@ -292,3 +292,70 @@ test("Javascript has regular expression literals and returns the regex group mat
});
+//STATEMENTS
+
+test("Javascript does not have block scope: variables inside a block leak out", function () {
+
+
+ var outsideBlock = 10;
+ if (outsideBlock == 10) {
+ var insideBlock = 99;
+ }
+
+ ok(insideBlock == 99);
+});
+
+test("Javascript has switch statements", function () {
+
+ var animal = "CAT";
+
+ function getSound() {
+ switch (animal)
+ {
+ case "CAT":
+ return "meow";
+ break;
+ case "DOG":
+ return "woof";
+ break;
+ case "PIDGIN":
+ return "gobble";
+ break;
+ default:
+ return "something else";
+ break;
+ }
+
+
+ }
+ ok(getSound() == "meow");
+});
+
+test("You can label statements so you can break them from an inner scope", function () {
+
+ // inner loop cancels outer look
+
+
+ var x = 0;
+ var z = 0
+ labelForOuterLoop: while (true) {
+ console.log("Outer loops: " + x);
+ x += 1;
+ z = 1;
+ while (true) {
+ console.log("Inner loops: " + z);
+ z += 1;
+ if (z === 10 && x === 10) {
+ break labelForOuterLoop;
+ } else if (z === 10) {
+ break;
+ }
+ }
+ }
+
+ ok(x == 10 && z == 10);
+});
+
+
+
+

0 comments on commit 61cbd3c

Please sign in to comment.