PHP Interview Questions(17)

面试时间:2020年1月7号,星期一,上午十点。


1.What does “&” mean in ‘&$var’?

Passing by Reference

https://www.php.net/manual/en/language.references.pass.php

2.What is MVC?

MVC is a design pattern used to decouple user-interface (view), data (model), and application logic (controller). This pattern helps to achieve separation of concerns.

https://dotnet.microsoft.com/apps/aspnet/mvc

3.What is the difference between $_GET and $_POST?

$_GET — HTTP GET variables
$_POST — HTTP POST variables

https://www.php.net/manual/en/reserved.variables.php

4.What will be the output of each statements below and why?

var_dump(0123 == 123);

var_dump(‘0123’ == 123);

var_dump(‘0123’ === 123);

False
True
False

https://www.php.net/manual/en/language.types.integer.php

5.After the code below is exexuted, what will be the value of $text and what will be strlen($text) return? Explain your answer.

$text = ‘John ‘;

$text[10] = ‘Doe’;

$text = 'John      D';
strlen($text) = 11;

Javascript

1.What is the potential pitfall with using typeof bar == “object” to determine if bar is an object? How can this pitfall be avoided?

typeof null == "object"
bar != null && typeof bar == "object"

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof

2.What is NaN? What is its type? How can you reliably test if a value is equal to NaN?

Not a number
Number
isNaN()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN

3.What is the difference between jQuery.get() and jQuery.ajax()?

$.get(url, data, success, dataType) is a shorthand Ajax function, which is equivalent to:

$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

https://api.jquery.com/jQuery.get/

4.Write a simple function(less than 80 characters) returns a boolean indicating whether or not a string is palindrome.

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers.

console.log(isPalindrome("level"));                    // logs 'true'
console.log(isPalindrome("levels"));                   // logs 'false'
console.log(isPalindrome("A car, a man, a maraca"));   // logs 'true'

function isPalindrome(str) {
    str = str.replace(/\W/g, "").toLowerCase();
    return str.split("").reverse().join("") == str;
}

636 total views, 15 views today